Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions esbuild.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const esbuild = require("esbuild");
import esbuild from "esbuild";

const production = process.argv.includes("--production");
const watch = process.argv.includes("--watch");
Expand Down Expand Up @@ -32,7 +32,7 @@ async function main() {
sourcemap: !production,
sourcesContent: false,
platform: "node",
outfile: "dist/extension.js",
outfile: "dist/extension.cjs",
external: ["vscode"],
logLevel: "silent",
plugins: [
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@
"activationEvents": [
"onStartupFinished"
],
"main": "dist/extension.js",
"main": "dist/extension.cjs",
"type": "module",
"private": true,
"icon": "assets/icon.png",
"scripts": {
Expand Down
38 changes: 21 additions & 17 deletions src/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,33 +72,38 @@ export class RPCController {
private listen() {
const config = getConfig();

const sendActivity = (isViewing = false, isIdling = false) => {
this.activityThrottle.reset();
void this.sendActivity(isViewing, isIdling);
};

const fileSwitch = window.onDidChangeActiveTextEditor(() => {
const fileSwitch = window.onDidChangeActiveTextEditor((e) => {
logInfo("onDidChangeActiveTextEditor()");
sendActivity(true);
if (e) {
this.activityThrottle.reset();
void this.activityThrottle.callable();
return;
}
setTimeout(() => {
this.checkIdle(window.state);
}, 500);
});
const fileEdit = workspace.onDidChangeTextDocument((e) => {
if (e.document !== dataClass.editor?.document) return;
logInfo("onDidChangeTextDocument()");
dataClass.updateGitInfo();
this.activityThrottle.reset();
void this.activityThrottle.callable();
});
const fileSelectionChanged = window.onDidChangeTextEditorSelection((e) => {
if (e.textEditor !== dataClass.editor) return;
logInfo("onDidChangeTextEditorSelection()");
dataClass.updateGitInfo();
this.activityThrottle.reset();
void this.activityThrottle.callable();
});
const debugStart = debug.onDidStartDebugSession(() => {
void this.activityThrottle.callable();
});
const debugEnd = debug.onDidTerminateDebugSession(() => {
void this.activityThrottle.callable();
});
const debugStart = debug.onDidStartDebugSession(() => sendActivity());
const debugEnd = debug.onDidTerminateDebugSession(() => sendActivity());
const diagnosticsChange = languages.onDidChangeDiagnostics(() => onDiagnosticsChange());
const changeWindowState = window.onDidChangeWindowState((e: WindowState) => {
logInfo("onDidChangeWindowState()");
dataClass.updateGitInfo();
this.checkIdle(e);
});

Expand Down Expand Up @@ -127,15 +132,15 @@ export class RPCController {
return (this.canSendActivity = true);
}

private async checkIdle(windowState: WindowState) {
private checkIdle(windowState: WindowState) {
if (!this.enabled) return;

const config = getConfig();

if (config.get(CONFIG_KEYS.Status.Idle.Timeout) !== 0) {
if (windowState.focused && this.idleTimeout) {
clearTimeout(this.idleTimeout);
await this.sendActivity();
void this.activityThrottle.callable();
} else if (config.get(CONFIG_KEYS.Status.Idle.Check)) {
this.idleTimeout = setTimeout(
async () => {
Expand All @@ -150,8 +155,7 @@ export class RPCController {

if (!this.enabled) return;

this.activityThrottle.reset();
await this.sendActivity(false, true);
void this.activityThrottle.callable(false, true);
},
config.get(CONFIG_KEYS.Status.Idle.Timeout)! * 1000
);
Expand Down Expand Up @@ -220,7 +224,7 @@ export class RPCController {
editor.setStatusBarItem(StatusBarMode.Succeeded);

logInfo("[004] Debug:", "Enabled - isConnected", this.client.isConnected, "isReady", this.client.clientId);
await this.sendActivity();
await this.activityThrottle.callable();
this.cleanUp();
this.listen();

Expand Down
15 changes: 11 additions & 4 deletions src/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,15 +159,22 @@ export class Data implements Disposable {
return v;
}

#lastValidGitRemoteUrl = "";

public get gitRemoteUrl(): gitUrlParse.GitUrl | undefined {
this.debug(`gitRemoteUrl(): Remote: ${this._remote}`);
const v = stripCredential(this._remote?.fetchUrl ?? this._remote?.pushUrl ?? "");
this.debug(`gitRemoteUrl(): Url: ${v ?? ""}`);
if (!v) return;

logInfo(`gitRemoteUrl(): Parsed: ${JSON.stringify(gitUrlParse(v), null, 2)}`);
const parsed = gitUrlParse(v);

if (this.#lastValidGitRemoteUrl !== v) {
this.#lastValidGitRemoteUrl = v;
this.debug(`gitRemoteUrl(): Remote: ${this._remote}`);
this.debug(`gitRemoteUrl(): Url: ${v ?? ""}`);
logInfo(`gitRemoteUrl(): Parsed: ${JSON.stringify(parsed, null, 2)}`);
}

return gitUrlParse(v);
return parsed;
}

public get gitBranchName(): string | undefined {
Expand Down