Skip to content

Commit

Permalink
Handle unsaved files in main language server client
Browse files Browse the repository at this point in the history
  • Loading branch information
vinistock committed Jun 3, 2024
1 parent cad8b88 commit e1fb043
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
15 changes: 14 additions & 1 deletion vscode/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
ExecutableOptions,
ServerOptions,
MessageSignature,
DocumentSelector,
} from "vscode-languageclient/node";

import { LSP_NAME, ClientInterface } from "./common";
Expand Down Expand Up @@ -92,6 +93,7 @@ function collectClientOptions(
workspaceFolder: vscode.WorkspaceFolder,
outputChannel: WorkspaceChannel,
ruby: Ruby,
mainWorkspace: boolean,
): LanguageClientOptions {
const pullOn: "change" | "save" | "both" =
configuration.get("pullDiagnosticsOn")!;
Expand All @@ -105,13 +107,22 @@ function collectClientOptions(
const enabledFeatures = Object.keys(features).filter((key) => features[key]);

const fsPath = workspaceFolder.uri.fsPath.replace(/\/$/, "");
const documentSelector = [
const documentSelector: DocumentSelector = [
{
language: "ruby",
pattern: `${fsPath}/**/*`,
},
];

// Only the first language server we spawn should handle unsaved files, otherwise requests will be duplicated across
// all workspaces
if (mainWorkspace) {
documentSelector.push({
language: "ruby",
scheme: "untitled",
});
}

if (ruby.env.GEM_PATH) {
const parts = ruby.env.GEM_PATH.split(path.delimiter);

Expand Down Expand Up @@ -161,6 +172,7 @@ export default class Client extends LanguageClient implements ClientInterface {
createTestItems: (response: CodeLens[]) => void,
workspaceFolder: vscode.WorkspaceFolder,
outputChannel: WorkspaceChannel,
mainWorkspace = false,
) {
super(
LSP_NAME,
Expand All @@ -170,6 +182,7 @@ export default class Client extends LanguageClient implements ClientInterface {
workspaceFolder,
outputChannel,
ruby,
mainWorkspace,
),
);

Expand Down
1 change: 1 addition & 0 deletions vscode/src/rubyLsp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ export class RubyLsp {
workspaceFolder,
this.telemetry,
this.testController.createTestItems.bind(this.testController),
eager,
);
this.workspaces.set(workspaceFolder.uri.toString(), workspace);

Expand Down
4 changes: 4 additions & 0 deletions vscode/src/workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export class Workspace implements WorkspaceInterface {
private readonly context: vscode.ExtensionContext;
private readonly telemetry: Telemetry;
private readonly outputChannel: WorkspaceChannel;
private readonly mainWorkspace: boolean;
private needsRestart = false;
#rebaseInProgress = false;
#error = false;
Expand All @@ -30,6 +31,7 @@ export class Workspace implements WorkspaceInterface {
workspaceFolder: vscode.WorkspaceFolder,
telemetry: Telemetry,
createTestItems: (response: CodeLens[]) => void,
mainWorkspace = false,
) {
this.context = context;
this.workspaceFolder = workspaceFolder;
Expand All @@ -40,6 +42,7 @@ export class Workspace implements WorkspaceInterface {
this.telemetry = telemetry;
this.ruby = new Ruby(context, workspaceFolder, this.outputChannel);
this.createTestItems = createTestItems;
this.mainWorkspace = mainWorkspace;

this.registerRestarts(context);
this.registerRebaseWatcher(context);
Expand Down Expand Up @@ -102,6 +105,7 @@ export class Workspace implements WorkspaceInterface {
this.createTestItems,
this.workspaceFolder,
this.outputChannel,
this.mainWorkspace,
);

try {
Expand Down

0 comments on commit e1fb043

Please sign in to comment.