Skip to content

Commit 7e44620

Browse files
fix: resolve workspace folder in config path for better compatibility
see #66 this allows use of relative path to the config file and variable use and makes the following valid configuration options: { vale.valeCLI.config: /home/patrick/github.com/davidsneighbour/kollitsch.dev/src/config/vale/vale.ini, vale.valeCLI.config: /src/config/vale/vale.ini, vale.valeCLI.config: ./src/config/vale/vale.ini, } Signed-off-by: Patrick Kollitsch <[email protected]>
1 parent ada0aea commit 7e44620

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

src/lsp.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,26 @@ export async function activate(context: ExtensionContext) {
148148
valeFilter = filters.join(" and ") as unknown as valeArgs;
149149
}
150150

151+
// Get the config path as a string
152+
let configPathRaw = configuration.get<string>("vale.valeCLI.config") || "";
153+
154+
// Resolve workspace folder
155+
let resolvedConfigPath = configPathRaw;
156+
if (vscode.workspace.workspaceFolders && vscode.workspace.workspaceFolders.length > 0) {
157+
const workspaceRoot = vscode.workspace.workspaceFolders[0].uri.fsPath;
158+
159+
if (configPathRaw.includes("${workspaceFolder}")) {
160+
resolvedConfigPath = configPathRaw.replace(/\$\{workspaceFolder\}/g, workspaceRoot);
161+
} else if (
162+
configPathRaw.startsWith("./") ||
163+
(!path.isAbsolute(configPathRaw) && configPathRaw.length > 0)
164+
) {
165+
resolvedConfigPath = path.join(workspaceRoot, configPathRaw);
166+
}
167+
}
168+
151169
let valeConfig: Record<valeConfigOptions, valeArgs> = {
152-
configPath: configuration.get("vale.valeCLI.config") as valeArgs,
170+
configPath: { value: resolvedConfigPath } as valeArgs,
153171
syncOnStartup: configuration.get("vale.valeCLI.syncOnStartup") as valeArgs,
154172
filter: valeFilter as unknown as valeArgs,
155173
// TODO: Build into proper onboarding

0 commit comments

Comments
 (0)