-
-
Notifications
You must be signed in to change notification settings - Fork 35
Adds support for workspace built-in variables #232
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
"use strict"; | ||
|
||
import * as os from "os"; | ||
import * as path from "path"; | ||
import * as cp from "child_process"; | ||
import ChildProcess = cp.ChildProcess; | ||
|
@@ -8,7 +9,7 @@ import { getIncludeParams, LANGUAGE_ID } from "../lib/helper"; | |
import * as vscode from "vscode"; | ||
|
||
export default class FortranLintingProvider { | ||
constructor() {} | ||
constructor() { } | ||
|
||
private diagnosticCollection: vscode.DiagnosticCollection; | ||
|
||
|
@@ -87,8 +88,8 @@ export default class FortranLintingProvider { | |
} | ||
|
||
private constructArgumentList(textDocument: vscode.TextDocument): string[] { | ||
let options = vscode.workspace.rootPath | ||
? { cwd: vscode.workspace.rootPath } | ||
let options = vscode.workspace.workspaceFolders | ||
? { cwd: vscode.workspace.workspaceFolders } | ||
: undefined; | ||
let args = [ | ||
"-fsyntax-only", | ||
|
@@ -164,14 +165,38 @@ export default class FortranLintingProvider { | |
let config = vscode.workspace.getConfiguration("fortran"); | ||
let includePaths: string[] = config.get("includePaths", []); | ||
|
||
return includePaths; | ||
return includePaths.map(this.resolveVariables); | ||
} | ||
private getGfortranPath(): string { | ||
let config = vscode.workspace.getConfiguration("fortran"); | ||
return config.get("gfortranExecutable", "gfortran"); | ||
} | ||
private getLinterExtraArgs(): string[] { | ||
let config = vscode.workspace.getConfiguration("fortran"); | ||
return config.get("linterExtraArgs", ["-Wall"]); | ||
let args = config.get("linterExtraArgs", ["-Wall"]); | ||
|
||
return args.map(this.resolveVariables); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. External args passed by the user can be anything, we should not be overriding them. It can break people's workflow. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think we would be overriding something the user can define outside of VS Code, since
However, gfortran does not declare arguments in this format, therefore, to the best of my knowledge Moreover, this is very similar to how the C/C++ extension works which allows for |
||
} | ||
|
||
/** | ||
* Resolve the absolute paths of built-in vscode variables | ||
* `${workspaceFolder}`, `${workspaceRoot}` and `~` | ||
*/ | ||
private resolveVariables(input: string): string { | ||
if (!input) { | ||
return ""; | ||
} | ||
|
||
// Get the top-most workspace folder | ||
const folder: vscode.WorkspaceFolder | undefined = vscode.workspace.workspaceFolders[0]; | ||
let ret: string = input; | ||
// Replace workspaceFolder and workspaceRoot with absolute workspace path | ||
ret = ret.replace(/(\${workspaceFolder}|\${workspaceRoot})/g, folder.uri.fsPath); | ||
|
||
// Resolve '~' at the start of the path. | ||
let regexp = () => /^\~/g; | ||
ret = ret.replace(regexp(), (match: string, name: string) => os.homedir()); | ||
|
||
return ret; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like this option is not used at all. When running the linter the cwd passed is the one of the active file. This works well for single files but I can imagine that it does not when working on a project context.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
True, I hadn't noticed I simply updated the
rootPath
option which was deprecated. I will removeoptions
completely.