-
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
Add a language label next to databases in the UI #697
Conversation
62654cc
to
5a4b479
Compare
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.
Refactoring looks good. I suggest getting the language from a CLI command instead of the YAML.
extensions/ql-vscode/src/helpers.ts
Outdated
'semmlecode.javascript.dbscheme': 'javascript', | ||
'semmlecode.cpp.dbscheme': 'cpp', | ||
'semmlecode.dbscheme': 'java', | ||
'semmlecode.python.dbscheme': 'pyhton', |
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.
'semmlecode.python.dbscheme': 'pyhton', | |
'semmlecode.python.dbscheme': 'python', |
extensions/ql-vscode/src/helpers.ts
Outdated
return !!path.basename(dbPath).startsWith('db-'); | ||
} | ||
|
||
export async function getPrimaryLanguage(root: string) { |
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.
Instead of parsing the config file, make a call to codeql resolve database --format json
and get the first value in the languages
field.
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.
Agreed. Especially because the open-sourced VSCode extension is our showcase for the Right way to do things.
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 will also mean that the extension will not need its own dbSchemeToLanguage
lookup table, since the codeql resolve database
now already tries a dbscheme-based heuristic for language detection.
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.
The reason I chose not to do that is that currently, there is no cli available on openDatabase
. Also, making a filesystem check will be faster than starting up a jvm to get this information.
I could certainly stuff a reference to the cli into the constructor. But I'd prefer not to do that for the reasons above unless the approach I'm taking would produce incorrect results.
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 would lean towards considering "people who write their own IDE integrations for CodeQL think this is the right thing to do, and proceed to bake half-understood internal knowledge of database internals into their own work" to be an incorrect result. :-)
On the other hand, I don't have the insight to appreciate the possible problems in dealing with "there is no cli available on openDatabase
". Why is that?
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.
The cli
is a singleton that gets passed around when needed. The DatabaseManager
does not hold a reference to the cli
. I would need to change that in order to call a cli command here. It's not a big change, but it is an architectural one.
Also, I still need dbSchemeToLanguage
as a fallback in case the database was not created by a modern CLI. I will add a comment around using that so it's known that this is not recommended.
So, the question is, should I be getting the database label from the codeql-database.yml
or from database resolve
? I'm not sure what your comment was on this or about the dbSchemeToLanguage
.
22afde9
to
7d86f1b
Compare
If the CLI is new enough to return
I think the extension should rely exclusively on |
Two questions:
EDIT: Looked at the code again and the answer to (2) seems to be "yes". |
Hmmyes, an existing quick-query feature of course needs to keep working. I was thinking more in terms of the new feature with showing language tags for databases in the UI. Here I think it is reasonably to expect that you need both a new extension and a CLI that supports the feature. |
This change will only work on databases created by cli >= 2.4.1. In that version, a new `primaryLanguage` field in the `codeql-database.yml` file. We use this property as the language. This change also includes a refactoring of the logic around extracting database information heuristically based on file location. As much as possible, it is extracted to the `helpers` module. Also, the initial quick query text is generated based on the language (if known) otherwise it falls back to the old style of generation.
This commit moves to using codeql resolve database instead of inspecting the `codeql-database.yml` file. When the extension starts and if the cli supports it, the extension will attempt to get the name for any databases that don't yet have a name. Once a name is searched for once by the cli, it will be cached so we don't need to rediscover the name again.
c75044f
to
dfbcf81
Compare
I think this addresses all the concerns. Look at the second commit for the changes. I rebased to remove merge conflicts. |
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 feel qualified to review the TS part, but I'm happy with the general approach to finding the language now.
extensions/ql-vscode/src/helpers.ts
Outdated
* CLI versions before the langauge name was introduced to dbInfo. Implementations | ||
* that do not require backwards compatibility should call | ||
* `cli.CodeQLCliServer.resolveDatabase` and use the first entry in the |
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.
Implementations
sounds like an "off" word to use here. Applications? Features?
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.
Features sounds good.
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.
A few minor questions.
extensions/ql-vscode/src/cli.ts
Outdated
@@ -123,6 +124,11 @@ export class CodeQLCliServer implements Disposable { | |||
*/ | |||
private static CLI_VERSION_WITH_DECOMPILE_KIND_DIL = new SemVer('2.3.0'); | |||
|
|||
/** | |||
* CLI version where --kind=DIL was introduced |
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.
Copy-paste comment.
extensions/ql-vscode/src/cli.ts
Outdated
return (await this.getVersion()).compare(CodeQLCliServer.CLI_VERSION_WITH_DECOMPILE_KIND_DIL) >= 0; | ||
} | ||
|
||
public async supportsLangaugeName() { |
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.
typo
|
||
private async getPrimaryLanguage(dbPath: string) { | ||
if (!(await this.cli.supportsLangaugeName())) { | ||
// return undefined so that we continually recalculate until the cli version is bumped |
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.
What do you mean by recalculate?
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'll explain better.
extensions/ql-vscode/src/helpers.ts
Outdated
* Returns the initial contents for an empty query, based on the language of the selected | ||
* databse. | ||
* | ||
* First try to get the contents text based on language. if that fails, try to get based on |
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.
* First try to get the contents text based on language. if that fails, try to get based on | |
* First try to use the given language name. If that doesn't exist, try to infer it based on |
extensions/ql-vscode/src/helpers.ts
Outdated
* CLI versions before the langauge name was introduced to dbInfo. Implementations | ||
* that do not require backwards compatibility should call | ||
* `cli.CodeQLCliServer.resolveDatabase` and use the first entry in the |
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.
Features sounds good.
This change will only work on databases created by cli >= 2.4.1. In that
version, a new
primaryLanguage
field in thecodeql-database.yml
file. We use this property as the language.
This change also includes a refactoring of the logic around extracting
database information heuristically based on file location. As much
as possible, it is extracted to the
helpers
module. Also, theinitial quick query text is generated based on the language (if known)
otherwise it falls back to the old style of generation.
Fixes #321
Checklist
@github/docs-content-dsp
has been cc'd in all issues for UI or other user-facing changes made by this pull request.