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

Fix the "CodeQL: Open Referenced File" command for windows paths #979

Merged
merged 1 commit into from
Oct 27, 2021

Conversation

mgsium
Copy link
Contributor

@mgsium mgsium commented Oct 21, 2021

Removes the leading '/' in a qlref query path if it's followed by a windows drive letter. Fixes #970

Checklist

  • CHANGELOG.md has been updated to incorporate all user visible changes made by this pull request.
  • (N/A) Issues have been created for any UI or other user-facing changes made by this pull request.
  • (N/A) @github/docs-content-codeql has been cc'd in all issues for UI or other user-facing changes made by this pull request.

@mgsium mgsium marked this pull request as ready for review October 21, 2021 09:08
@mgsium mgsium requested a review from a team as a code owner October 21, 2021 09:08
Copy link
Contributor

@shati-patel shati-patel left a 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 😅)

extensions/ql-vscode/CHANGELOG.md Outdated Show resolved Hide resolved
@mgsium mgsium changed the title Windows paths Fix the "CodeQL: Open Referenced File" command for windows paths Oct 21, 2021
@mgsium mgsium requested a review from aeisenberg October 21, 2021 15:48
Copy link
Contributor

@adityasharad adityasharad left a 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'));
Copy link
Contributor

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?

Copy link
Contributor Author

@mgsium mgsium Oct 21, 2021

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);

Copy link
Contributor

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.

Copy link
Contributor Author

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?

Copy link
Contributor

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.

Copy link
Contributor

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/src/extension.ts Outdated Show resolved Hide resolved
extensions/ql-vscode/src/extension.ts Outdated Show resolved Hide resolved
Comment on lines 19 to 22
- 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)

Copy link
Contributor

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.

Comment on lines 503 to 508
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);
Copy link
Contributor

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?

Suggested change
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.

Copy link
Contributor Author

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

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great!

Copy link
Contributor

@aeisenberg aeisenberg left a 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.

@aeisenberg aeisenberg enabled auto-merge October 27, 2021 15:59
@aeisenberg aeisenberg merged commit 0a0500a into github:main Oct 27, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

"CodeQL: Open Referenced File" command fails on Windows
4 participants