Skip to content

Commit

Permalink
feat(lsp): Allow passing environment variables to the language server (
Browse files Browse the repository at this point in the history
…#438)

This adds an extra configuration option, `bazel.lsp.env`, which passes extra environment variables to the language server. This is useful to enable logging, for example.
  • Loading branch information
cameron-martin authored Feb 15, 2025
1 parent 7e5ee8f commit 0dc2684
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
8 changes: 8 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,14 @@
"default": [],
"description": "The arguments to pass to the LSP executable"
},
"bazel.lsp.env": {
"type": "object",
"default": {},
"additionalProperties": {
"type": "string"
},
"description": "Environment variables to pass to the LSP executable"
},
"bazel.trace.server": {
"type": "string",
"enum": [
Expand Down
21 changes: 13 additions & 8 deletions src/extension/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,7 @@
// limitations under the License.

import * as vscode from "vscode";
import {
LanguageClient,
LanguageClientOptions,
ServerOptions,
} from "vscode-languageclient/node";
import * as lc from "vscode-languageclient/node";

import { activateTaskProvider, IBazelCommandAdapter } from "../bazel";
import {
Expand Down Expand Up @@ -181,17 +177,26 @@ export function deactivate() {
function createLsp(config: vscode.WorkspaceConfiguration) {
const command = config.get<string>("lsp.command");
const args = config.get<string[]>("lsp.args");
const env = config.get<Record<string, string>>("lsp.env");

const serverOptions: ServerOptions = {
const run: lc.Executable = {
args,
command,
options: {
env: { ...process.env, ...env },
},
};

const serverOptions: lc.ServerOptions = {
run,
debug: run,
};

const clientOptions: LanguageClientOptions = {
const clientOptions: lc.LanguageClientOptions = {
documentSelector: [{ scheme: "file", language: "starlark" }],
};

return new LanguageClient(
return new lc.LanguageClient(
"bazel",
"Bazel LSP Client",
serverOptions,
Expand Down

0 comments on commit 0dc2684

Please sign in to comment.