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

resolve ${workspaceFolder} in erlang configuration for erlangPath and… #299

Merged
merged 2 commits into from
Jun 1, 2024
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
4 changes: 3 additions & 1 deletion .github/workflows/pr-verify.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ jobs:
node:
- 20
steps:
- run: sudo apt-get install erlang
- run: |
sudo apt-get update
sudo apt-get install erlang
if: runner.os == 'Linux'
- run: |
brew install erlang@26
Expand Down
51 changes: 37 additions & 14 deletions lib/ErlangConfigurationProvider.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import {
workspace, WorkspaceFolder, DebugConfiguration, DebugConfigurationProvider, CancellationToken, ProviderResult
} from 'vscode';
import {
workspace, WorkspaceFolder, DebugConfiguration, DebugConfigurationProvider, CancellationToken, ProviderResult, WorkspaceConfiguration
} from 'vscode';
import { ErlangSettings } from './erlangSettings';
import { stringify } from 'querystring';
//import { ErlangOutput } from './vscodeAdapter';

export class ErlangDebugConfigurationProvider implements DebugConfigurationProvider {
provideDebugConfigurations?(folder: WorkspaceFolder | undefined, token?: CancellationToken): ProviderResult<DebugConfiguration[]> {
if (folder) {
return [];
return [];
}
return undefined;
}
Expand All @@ -20,37 +21,59 @@ export class ErlangDebugConfigurationProvider implements DebugConfigurationProvi
}
};

let currentSettings : ErlangSettings = null;
let currentSettings: ErlangSettings = null;

export function configurationChanged() : void {
export function configurationChanged(): void {
let erlangConf = workspace.getConfiguration("erlang");
let settings : ErlangSettings = {
erlangPath: erlangConf.get<string>("erlangPath", null),
let settings: ErlangSettings = {
erlangPath: resolveVariables(erlangConf.get<string>("erlangPath", null)),
erlangArgs: erlangConf.get("erlangArgs", []),
erlangDistributedNode: erlangConf.get("erlangDistributedNode", false),
rebarPath: erlangConf.get<string>("rebarPath", null),
rebarPath: resolveVariables(erlangConf.get<string>("rebarPath", null)),
codeLensEnabled: erlangConf.get<boolean>('codeLensEnabled', false),
inlayHintsEnabled: erlangConf.get<boolean>('inlayHintsEnabled', false),
debuggerRunMode: erlangConf.get<string>("debuggerRunMode", "Server"),
includePaths: erlangConf.get("includePaths", []),
linting: erlangConf.get<boolean>('linting', false),
rebarBuildArgs: erlangConf.get("rebarBuildArgs", ['compile']),
rootPath : extractRootPath(),
rootPath: extractRootPath(),
verbose: erlangConf.get("verbose", false)
};
currentSettings = settings;
}

function extractRootPath() : string {
//workspace.rootPath is deprecated, and documentation notice that value is store in first workspace folder
export function resolveErlangSettings(erlangSection : WorkspaceConfiguration): any {
const erlangconfigAsJson = JSON.stringify(erlangSection);
const erlangConfiguration = JSON.parse(erlangconfigAsJson);
if (erlangConfiguration) {
erlangConfiguration.erlangPath = resolveVariables(erlangConfiguration.erlangPath);
erlangConfiguration.rebarPath = resolveVariables(erlangConfiguration.rebarPath);
}
return erlangConfiguration;
}

function getFirstWorkspaceFolderPath(): string {
let folders = workspace.workspaceFolders;
if (folders && folders.length > 0) {
return folders[0].uri.fsPath;
}
return undefined;
return "";
}

function extractRootPath(): string {
const res = getFirstWorkspaceFolderPath();
return res != "" ? res : undefined;
}

function resolveVariables(value: string) : string {
//https://code.visualstudio.com/docs/editor/variables-reference#_predefined-variables
if (!value) return value;
value = value.replace('${workspaceFolder}', getFirstWorkspaceFolderPath);
return value;
}

export function getElangConfigConfiguration() : ErlangSettings {

export function getElangConfigConfiguration(): ErlangSettings {
if (!currentSettings) {
configurationChanged();
// in order to debug
Expand Down
4 changes: 2 additions & 2 deletions lib/eunitRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ function readRebarConfigWithErlangShell(): Thenable<CompileArgs> {
return new Promise<CompileArgs>((a, r) => {
const rootPath = getElangConfigConfiguration().rootPath;
var erlangShell = new erlang.ErlangShell();
erlangShell.erlangPath = vscode.workspace.getConfiguration("erlang").get("erlangPath", null);
erlangShell.erlangPath = getElangConfigConfiguration().erlangPath;

erlangShell.Start(rootPath, []).then(
_ => {
Expand Down Expand Up @@ -289,7 +289,7 @@ function compile(compileArgs: CompileArgs): Thenable<string[]> {
}).then(args => {
var argsCmd = args.IncludeDirs.concat(["-o", eunitDirectory]).concat(args.ErlangFiles);
var erlc = new erlang.ErlangCompilerShell();
erlc.erlangPath = vscode.workspace.getConfiguration("erlang").get("erlangPath", null);
erlc.erlangPath = getElangConfigConfiguration().erlangPath;
return erlc.Start(rootPath, argsCmd.map<string>(x => x.toString()))
.then(exitCode => {
return args.ErlangFiles;
Expand Down
4 changes: 3 additions & 1 deletion lib/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ export function activate(context: ExtensionContext) {
eunit.activate(context);

disposables.push(debug.registerDebugConfigurationProvider("erlang", new ErlangDebugConfigurationProvider()));
disposables.push(Workspace.onDidChangeConfiguration((e) => configurationChanged()));
disposables.push(Workspace.onDidChangeConfiguration((e) => configurationChanged()));
disposables.push(Workspace.onDidChangeWorkspaceFolders((e) => configurationChanged()));

let runMode = getElangConfigConfiguration().debuggerRunMode;
let factory: DebugAdapterDescriptorFactory;
switch (runMode) {
Expand Down
12 changes: 4 additions & 8 deletions lib/lsp/lspclientextension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import * as lspRename from './lsp-rename';
// import { ErlangSettings } from '../erlangSettings';
import RebarShell from '../RebarShell';
import { ErlangOutputAdapter } from '../vscodeAdapter';
import { getElangConfigConfiguration } from '../ErlangConfigurationProvider';
import { getElangConfigConfiguration, resolveErlangSettings } from '../ErlangConfigurationProvider';
import { ErlangLanguageClient, erlangDocumentSelector } from './lsp-context';

/*
Expand Down Expand Up @@ -67,8 +67,6 @@ namespace Configuration {
// both client and server do use JSON the conversion is trivial.
export function computeConfiguration(params: ConfigurationParams, _token: CancellationToken, _next: Function): any[] {

//lspOutputChannel.appendLine("computeConfiguration :"+ JSON.stringify(params));

if (!params.items) {
return null;
}
Expand All @@ -80,6 +78,8 @@ namespace Configuration {
autosave: Workspace.getConfiguration("files").get("autoSave", "afterDelay") === "afterDelay",
tmpdir: os.tmpdir()
});
} else if (item.section === "erlang") {
result.push(resolveErlangSettings(Workspace.getConfiguration(item.section)))
}
else {
result.push(Workspace.getConfiguration(item.section));
Expand Down Expand Up @@ -225,11 +225,7 @@ export function activate(context: ExtensionContext) {
didSave: (data: TextDocument, next: (data: TextDocument) => void) => {
next(data);//call LSP
lspcodelens.onDocumentDidSave();
},
// prepareRename: (document, position, token, next) => {
// return Promise.resolve(lspRename.onPrepareRename(document, position, token, next));

// },
},
};
// Options to control the language client
let clientOptions: LanguageClientOptions = {
Expand Down