Skip to content

Commit

Permalink
add getWorkspaceRootPaths util (#1389)
Browse files Browse the repository at this point in the history
  • Loading branch information
yonip23 authored Nov 30, 2023
1 parent 0d3a812 commit 6ee3820
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 32 deletions.
31 changes: 3 additions & 28 deletions src/WorkspaceUpdater.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import * as vscode from "vscode";
import { BINARY_UPDATE_WORKSPACE_INTERVAL } from "./globals/consts";
import sendUpdateWorkspaceRequest from "./binary/requests/workspace";
import { Logger } from "./utils/logger";
import { fireEvent, tabNineProcess } from "./binary/requests/requests";
import { Capability, isCapabilityEnabled } from "./capabilities/capabilities";
import { tabNineProcess } from "./binary/requests/requests";
import { getWorkspaceRootPaths } from "./utils/workspaceFolders";

const INITIAL_DELAY = 3000;

Expand All @@ -29,40 +29,15 @@ export class WorkspaceUpdater implements vscode.Disposable {
}
}

function sendEvent(event: string, payload: Record<string, unknown> = {}) {
if (isCapabilityEnabled(Capability.WORKSPACE_TRACE)) {
void fireEvent({
name: event,
...payload,
});
}
}

function updateWorkspace() {
sendEvent("workspace_starting");
const rootPaths =
vscode.workspace.workspaceFolders
?.filter((wf) => {
const isFileUrl = wf.uri.scheme === "file";
if (!isFileUrl) {
sendEvent("workspace_protocol_not_file", {
path: wf.uri.toString(),
});
}
return isFileUrl;
})
.map((wf) => wf.uri.fsPath) || [];
const rootPaths = getWorkspaceRootPaths() || [];

Logger.debug(
`Updating root paths for project ${
vscode.workspace.name || "unknown"
}: ${JSON.stringify(rootPaths)}`
);

sendEvent("workspace_sending_request", {
root_paths_len: rootPaths.length,
});

void sendUpdateWorkspaceRequest({
root_paths: rootPaths,
});
Expand Down
1 change: 0 additions & 1 deletion src/capabilities/capabilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ export enum Capability {
TEST_GEN = "vscode_test_gen",
FORCE_REGISTRATION = "plugin.feature.force_registration",
TABNINE_CHAT = "plugin.feature.tabnine_chat",
WORKSPACE_TRACE = "plugin.feature.workspace_trace",
}

let enabledCapabilities: Record<string, boolean> | null = null;
Expand Down
5 changes: 2 additions & 3 deletions src/tabnineChatWidget/ChatApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import {
NavigateToLocationPayload,
navigateToLocation,
} from "./handlers/navigateToLocation";
import { getWorkspaceRootPaths } from "../utils/workspaceFolders";

type GetUserResponse = {
token: string;
Expand Down Expand Up @@ -235,9 +236,7 @@ export function initChatApi(
.registerEvent<void, WorkspaceFolders | undefined>(
"workspace_folders",
() => {
const rootPaths = vscode.workspace.workspaceFolders
?.filter((wf) => wf.uri.scheme === "file")
.map((wf) => wf.uri.fsPath);
const rootPaths = getWorkspaceRootPaths();
if (!rootPaths) return undefined;

return {
Expand Down
7 changes: 7 additions & 0 deletions src/utils/workspaceFolders.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import * as vscode from "vscode";

export function getWorkspaceRootPaths() {
return vscode.workspace.workspaceFolders
?.filter((wf) => wf.uri.scheme === "file")
.map((wf) => wf.uri.fsPath);
}

0 comments on commit 6ee3820

Please sign in to comment.