-
Notifications
You must be signed in to change notification settings - Fork 191
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
Fix the "CodeQL: Open Referenced File" command for windows paths #979
Conversation
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.
This is great! Works for me (on Windows) too 🎉
(I'll let someone else approve/merge too, mainly cause I'm not super confident with regex/TS yet myself 😅)
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 good. Minor suggestions only, either for now or a follow-up.
let resolved; | ||
try { | ||
// replaces leading '/' in the query path if followed by a windows drive letter | ||
resolved = await cliServer.resolveQlref(selectedQuery.path.replace(/^\/([a-zA-Z]:)/, '$1')); |
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.
Should we detect whether the current OS is Windows, and only apply this replacement in that case?
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.
My thinking was a regex check for the drive letter at the start would be enough, but if not I could change it to something like:
let queryPath: string = selectedQuery.path;
if (process.platform === 'win32') {
queryPath = queryPath.replace(/^\/([a-zA-Z]:)/, '$1');
}
resolved = await cliServer.resolveQlref(queryPath);
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.
That looks nice and clear to me, together with your existing code comment. A file or directory on Unix with a colon is I think unlikely, but it's helpful to avoid that case entirely.
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.
Am I ok to add https://www.npmjs.com/package/platform as a dependency?
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.
I don't think you need that. You can use os.type()
https://nodejs.dev/learn/the-nodejs-os-module#ostype I think this is sufficient.
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.
process.platform
should work too.
extensions/ql-vscode/CHANGELOG.md
Outdated
- Remove line about selecting a language from the dropdown when downloading database from LGTM. This makes the download progress visible when the popup is not expanded. [#894](https://github.com/github/vscode-codeql/issues/894) | ||
- Fixed a bug where copying the version information fails when a CodeQL CLI cannot be found. [#958](https://github.com/github/vscode-codeql/pull/958) | ||
- Fixed _CodeQL: Open Referenced File_ command for windows systems. [#979](https://github.com/github/vscode-codeql/pull/979) | ||
|
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.
This needs to be deleted.
let queryPath: string = selectedQuery.path; | ||
if (os.type() === 'Windows_NT') { | ||
// replaces leading '/' in the query path if followed by a windows drive letter | ||
queryPath = queryPath.replace(/^\/([a-zA-Z]:)/, '$1'); | ||
} | ||
resolved = await cliServer.resolveQlref(queryPath); |
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.
I just realized now that it might just work with selectedQuery.fsPath
. Could you try this out?
let queryPath: string = selectedQuery.path; | |
if (os.type() === 'Windows_NT') { | |
// replaces leading '/' in the query path if followed by a windows drive letter | |
queryPath = queryPath.replace(/^\/([a-zA-Z]:)/, '$1'); | |
} | |
resolved = await cliServer.resolveQlref(queryPath); | |
resolved = await cliServer.resolveQlref(selectedQuery.fsPath); |
Sorry for not thinking of this earlier.
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.
Appears to work well on Windows and MacOS, I'll commit the change but with a const
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.
Great!
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.
Nice and simple. Even though the final change is small, I know there was a lot of work that went into this.
Removes the leading '/' in a qlref query path if it's followed by a windows drive letter. Fixes #970
Checklist
@github/docs-content-codeql
has been cc'd in all issues for UI or other user-facing changes made by this pull request.