Skip to content

Commit

Permalink
fix(launch): set workspaceFolder to where Chart.yaml is
Browse files Browse the repository at this point in the history
  • Loading branch information
qvalentin committed Jan 6, 2024
1 parent 5e498a2 commit a874468
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,12 @@ import {
LanguageClientOptions,
ServerOptions,
TransportKind,
WorkspaceFolder,
} from "vscode-languageclient/node";
import { getHelmLsExecutable } from "./util/executable";
import path from "path";
import fs from "fs";
import url from "url";

let client: LanguageClient;

Expand All @@ -21,10 +25,27 @@ export async function activate(_: vscode.ExtensionContext) {

console.log("Launching " + helmLsExecutable);

const workSpacePath = vscode.workspace.workspaceFolders?.[0].uri.path;
const filePath = vscode.window.activeTextEditor?.document.fileName;
var cwd: string

console.log("Workspace path: " + workSpacePath, "File path: " + filePath);
if (workSpacePath && fs.existsSync(path.join(workSpacePath, "Chart.yaml"))) {
console.log("Setting cwd to " + workSpacePath);
cwd = workSpacePath
}
else if (filePath) {
console.log("Setting cwd to " + traversePathUpToChartYaml(filePath));
cwd = traversePathUpToChartYaml(filePath)
}

const executable: Executable = {
command: helmLsExecutable,
args: ["serve"],
transport: TransportKind.stdio,
options: {
cwd: cwd
}
};

const serverOptions: ServerOptions = {
Expand All @@ -35,6 +56,10 @@ export async function activate(_: vscode.ExtensionContext) {
const clientOptions: LanguageClientOptions = {
documentSelector: [{ scheme: "file", language: "helm" }],
synchronize: {},
workspaceFolder: {
uri: url.pathToFileURL(cwd),
name: vscode.workspace.workspaceFolders?.[0].name,
}
};

client = new LanguageClient(
Expand All @@ -54,3 +79,14 @@ export function deactivate(): Thenable<void> | undefined {
}
return client.stop();
}

function traversePathUpToChartYaml(directory: string): string {
if (fs.existsSync(path.join(directory, "Chart.yaml"))) {
return directory
}
const parent = path.dirname(directory)
if (parent === "/") {
return ""
}
return traversePathUpToChartYaml(parent)
}

0 comments on commit a874468

Please sign in to comment.