Skip to content

Commit e1bb080

Browse files
fix: resolve workspace folder in config path for better compatibility (#70)
* 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]> * Add details to read me and settings UI --------- Signed-off-by: Patrick Kollitsch <[email protected]> Co-authored-by: Chris Chinchilla <[email protected]>
1 parent ada0aea commit e1bb080

File tree

3 files changed

+21
-3
lines changed

3 files changed

+21
-3
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ The extension doesn't support adding words to dictionaries. For now, the best op
6464

6565
The extension offers a number of settings and configuration options (_Preferences > Extensions > Vale_).
6666

67-
- `vale.valeCLI.config` (default: `null`): Absolute path to a Vale configuration file.
67+
- `vale.valeCLI.config` (default: `null`): Absolute or relative path to a Vale configuration file.
6868
- `vale.valeCLI.minAlertLevel` (default: `inherited`): Defines from which level of errors and above to display in the problems view.
6969
- `vale.doNotShowWarningForFileToBeSavedBeforeLinting` (default: `false`): Toggle display of warning dialog that you must save a file before Vale lints it.
7070
- `vale.readabilityProblemLocation` (default: `status`): If you have any `Readability` or `metric` styles, the extension can display the readability score in the status bar, the problems view, or both.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
"scope": "resource",
5757
"type": "string",
5858
"default": null,
59-
"description": "Absolute path to a Vale config file. If not specified, the default search process is used (relative to the current file)."
59+
"description": "Absolute or relative path to a Vale config file. If not specified, the default search process is used (relative to the current file)."
6060
},
6161
"vale.valeCLI.syncOnStartup": {
6262
"scope": "resource",

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)