Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DEV2-4390 add getWorkspaceRootPaths util #1389

Merged
merged 1 commit into from
Nov 30, 2023
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
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);
}
Loading