Skip to content

Conversation

@mgsium
Copy link
Contributor

@mgsiummgsium 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.

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

@shati-patelshati-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 😅)

@mgsiummgsium changed the title Windows pathsFix the "CodeQL: Open Referenced File" command for windows pathsOct 21, 2021
Copy link
Contributor

@adityasharadadityasharad 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.

letresolved;
try{
// replaces leading '/' in the query path if followed by a windows drive letter
resolved=awaitcliServer.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
ContributorAuthor

@mgsiummgsiumOct 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:

letqueryPath: string=selectedQuery.path;if(process.platform==='win32'){queryPath=queryPath.replace(/^\/([a-zA-Z]:)/,'$1');}resolved=awaitcliServer.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
ContributorAuthor

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.

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
letqueryPath: 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=awaitcliServer.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
letqueryPath: 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=awaitcliServer.resolveQlref(queryPath);
resolved=awaitcliServer.resolveQlref(selectedQuery.fsPath);

Sorry for not thinking of this earlier.

Copy link
ContributorAuthor

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

@aeisenbergaeisenberg 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.

@aeisenbergaeisenberg merged commit 0a0500a into github:mainOct 27, 2021
Sign up for freeto 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

@mgsium@aeisenberg@adityasharad@shati-patel