Skip to content

Commit

Permalink
Fixes path is relative to workspace root #248 (#249)
Browse files Browse the repository at this point in the history
  • Loading branch information
Real-Gecko authored Dec 3, 2024
1 parent c188207 commit 35ef42b
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 10 deletions.
2 changes: 2 additions & 0 deletions lsp/client/vscode/src/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export const defaultCommand = "grpc-federation-language-server";
export const configName = "grpc-federation";
38 changes: 28 additions & 10 deletions lsp/client/vscode/src/extension.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,47 @@
import * as path from 'path';
import { workspace, ExtensionContext } from 'vscode';
import { ExtensionContext, workspace } from 'vscode';

import {
LanguageClient,
LanguageClientOptions,
ServerOptions,
} from 'vscode-languageclient/node';
import * as constants from './constants';

let client: LanguageClient;

function getCommand(cmdPath: string, workspacePath: string) {
if (path.isAbsolute(cmdPath) || cmdPath == constants.defaultCommand)
return cmdPath;

return path.join(workspacePath, cmdPath);
}

function getArgs(importPaths: string[], workspacePath: string) {
const paths: string[] = [];
for (const importPath of importPaths) {
if (path.isAbsolute(importPath))
paths.push(importPath);
else
paths.push(path.join(workspacePath, importPath));
}
return paths.map((path) => { return `-I${path}`; });
}

export function activate(context: ExtensionContext) {
const config = workspace.getConfiguration("grpc-federation");
const cmdPath = config.get<string>("path");
const importPaths = config.get<string[]>("import-paths");
const config = workspace.getConfiguration(constants.configName);
const cmdPath = config.get<string>("path", constants.defaultCommand);
const importPaths = config.get<string[]>("import-paths", []);
const folders = workspace.workspaceFolders;
const defaultCommand = "grpc-federation-language-server"

let serverOptions: ServerOptions
let serverOptions: ServerOptions;
if (folders.length != 0) {
const uri = folders[0].uri;
const command = cmdPath ? path.join(uri.path, cmdPath) : defaultCommand;
const args = importPaths.map((importPath) => { return `-I${path.join(uri.path, importPath)}` });
serverOptions = {command: command, args: args};
const command = getCommand(cmdPath, uri.path);
const args = getArgs(importPaths, uri.path);
serverOptions = { command: command, args: args };
} else {
serverOptions = {command: defaultCommand }
serverOptions = { command: constants.defaultCommand };
}

const clientOptions: LanguageClientOptions = {
Expand Down

0 comments on commit 35ef42b

Please sign in to comment.