-
Notifications
You must be signed in to change notification settings - Fork 226
Fix naming and availability in command palette of various commands #377
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
d92edfb
ab09cdb
c017728
dd1bdf5
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 |
|---|---|---|
|
|
@@ -27,11 +27,13 @@ | |
| "onView:codeQLQueryHistory", | ||
| "onView:test-explorer", | ||
| "onCommand:codeQL.checkForUpdatesToCLI", | ||
| "onCommand:codeQLDatabases.chooseDatabaseFolder", | ||
| "onCommand:codeQLDatabases.chooseDatabaseArchive", | ||
| "onCommand:codeQLDatabases.chooseDatabaseInternet", | ||
| "onCommand:codeQL.setCurrentDatabase", | ||
| "onCommand:codeQL.chooseDatabaseFolder", | ||
| "onCommand:codeQL.chooseDatabaseArchive", | ||
| "onCommand:codeQL.chooseDatabaseInternet", | ||
| "onCommand:codeQL.setCurrentDatabase", | ||
| "onCommand:codeQL.downloadDatabase", | ||
| "onCommand:codeQLDatabases.chooseDatabase", | ||
| "onCommand:codeQLDatabases.setCurrentDatabase", | ||
| "onCommand:codeQL.quickQuery", | ||
|
|
@@ -175,24 +177,24 @@ | |
| "title": "CodeQL: Quick Query" | ||
| }, | ||
| { | ||
| "command": "codeQL.chooseDatabaseFolder", | ||
| "command": "codeQLDatabases.chooseDatabaseFolder", | ||
| "title": "Choose Database from Folder", | ||
| "icon": { | ||
| "light": "media/light/folder-opened-plus.svg", | ||
| "dark": "media/dark/folder-opened-plus.svg" | ||
| } | ||
| }, | ||
| { | ||
| "command": "codeQL.chooseDatabaseArchive", | ||
| "command": "codeQLDatabases.chooseDatabaseArchive", | ||
| "title": "Choose Database from Archive", | ||
| "icon": { | ||
| "light": "media/light/archive-plus.svg", | ||
| "dark": "media/dark/archive-plus.svg" | ||
| } | ||
| }, | ||
| { | ||
| "command": "codeQL.chooseDatabaseInternet", | ||
| "title": "Download database", | ||
| "command": "codeQLDatabases.chooseDatabaseInternet", | ||
| "title": "Download Database", | ||
| "icon": { | ||
| "light": "media/light/cloud-download.svg", | ||
| "dark": "media/dark/cloud-download.svg" | ||
|
|
@@ -231,8 +233,16 @@ | |
| "title": "Show Database Directory" | ||
| }, | ||
| { | ||
| "command": "codeQL.downloadDatabase", | ||
| "title": "CodeQL: Download database" | ||
| "command": "codeQL.chooseDatabaseFolder", | ||
| "title": "CodeQL: Choose Database from Folder" | ||
| }, | ||
| { | ||
| "command": "codeQL.chooseDatabaseArchive", | ||
| "title": "CodeQL: Choose Database from Archive" | ||
| }, | ||
| { | ||
| "command": "codeQL.chooseDatabaseInternet", | ||
| "title": "CodeQL: Download Database" | ||
| }, | ||
| { | ||
| "command": "codeQLDatabases.sortByName", | ||
|
|
@@ -312,17 +322,17 @@ | |
| "group": "navigation" | ||
| }, | ||
| { | ||
| "command": "codeQL.chooseDatabaseFolder", | ||
| "command": "codeQLDatabases.chooseDatabaseFolder", | ||
| "when": "view == codeQLDatabases", | ||
| "group": "navigation" | ||
| }, | ||
| { | ||
| "command": "codeQL.chooseDatabaseArchive", | ||
| "command": "codeQLDatabases.chooseDatabaseArchive", | ||
| "when": "view == codeQLDatabases", | ||
| "group": "navigation" | ||
| }, | ||
| { | ||
| "command": "codeQL.chooseDatabaseInternet", | ||
| "command": "codeQLDatabases.chooseDatabaseInternet", | ||
| "when": "view == codeQLDatabases", | ||
| "group": "navigation" | ||
| } | ||
|
|
@@ -406,10 +416,6 @@ | |
| "command": "codeQL.runQuery", | ||
| "when": "resourceLangId == ql && resourceExtname == .ql" | ||
| }, | ||
| { | ||
| "command": "codeQL.downloadDatabase", | ||
| "when": "true" | ||
| }, | ||
| { | ||
| "command": "codeQL.quickEval", | ||
| "when": "editorLangId == ql" | ||
|
|
@@ -442,6 +448,22 @@ | |
| "command": "codeQLDatabases.removeDatabase", | ||
| "when": "false" | ||
| }, | ||
| { | ||
| "command": "codeQLDatabases.chooseDatabaseFolder", | ||
|
Contributor
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. Do we want to disable these as global commands?
Contributor
Author
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. We definitely do want to disable these commands if we want to consistently maintain the pattern that the hover text over the buttons is not be prefixed, and the command palette command names is prefixed with However, we totally could also have command-palette-visible commands (which would be named, like,
Contributor
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. That makes sense. Maybe we don't want to pollute the global scope here with commands that are so tightly related to the databases view (I'm contradicting what I said earlier). So, what you have right now is fine. |
||
| "when": "false" | ||
| }, | ||
| { | ||
| "command": "codeQLDatabases.chooseDatabaseArchive", | ||
| "when": "false" | ||
| }, | ||
| { | ||
| "command": "codeQLDatabases.chooseDatabaseInternet", | ||
| "when": "false" | ||
| }, | ||
| { | ||
| "command": "codeQLDatabases.upgradeDatabase", | ||
| "when": "false" | ||
| }, | ||
| { | ||
| "command": "codeQLQueryHistory.openQuery", | ||
| "when": "false" | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,101 @@ | ||
| import { expect } from 'chai'; | ||
| import * as path from 'path'; | ||
| import * as fs from 'fs-extra'; | ||
|
|
||
| type CmdDecl = { | ||
| command: string; | ||
| when?: string; | ||
| title?: string; | ||
| } | ||
|
|
||
| describe('commands declared in package.json', function() { | ||
| const manifest = fs.readJsonSync(path.join(__dirname, '../../package.json')); | ||
| const commands = manifest.contributes.commands; | ||
| const menus = manifest.contributes.menus; | ||
|
|
||
| const disabledInPalette: Set<string> = new Set<string>(); | ||
|
|
||
| // These commands should appear in the command palette, and so | ||
| // should be prefixed with 'CodeQL: '. | ||
| const paletteCmds: Set<string> = new Set<string>(); | ||
|
|
||
| // These commands arising on context menus in non-CodeQL controlled | ||
| // panels, (e.g. file browser) and so should be prefixed with 'CodeQL: '. | ||
| const contribContextMenuCmds: Set<string> = new Set<string>(); | ||
|
|
||
| // These are commands used in CodeQL controlled panels, and so don't need any prefixing in their title. | ||
| const scopedCmds: Set<string> = new Set<string>(); | ||
| const commandTitles: { [cmd: string]: string } = {}; | ||
|
|
||
| commands.forEach((commandDecl: CmdDecl) => { | ||
| const { command, title } = commandDecl; | ||
| if (command.match(/^codeQL\./) | ||
| || command.match(/^codeQLQueryResults\./) | ||
| || command.match(/^codeQLTests\./)) { | ||
| paletteCmds.add(command); | ||
| expect(title).not.to.be.undefined; | ||
| commandTitles[command] = title!; | ||
| } | ||
| else if (command.match(/^codeQLDatabases\./) | ||
| || command.match(/^codeQLQueryHistory\./)) { | ||
| scopedCmds.add(command); | ||
| expect(title).not.to.be.undefined; | ||
| commandTitles[command] = title!; | ||
| } | ||
| else { | ||
| expect.fail(`Unexpected command name ${command}`); | ||
| } | ||
| }); | ||
|
|
||
| menus['explorer/context'].forEach((commandDecl: CmdDecl) => { | ||
| const { command } = commandDecl; | ||
| paletteCmds.delete(command); | ||
| contribContextMenuCmds.add(command); | ||
| }); | ||
|
|
||
| menus['editor/context'].forEach((commandDecl: CmdDecl) => { | ||
| const { command } = commandDecl; | ||
| paletteCmds.delete(command); | ||
| contribContextMenuCmds.add(command); | ||
| }); | ||
|
|
||
| menus.commandPalette.forEach((commandDecl: CmdDecl) => { | ||
| if (commandDecl.when === 'false') | ||
| disabledInPalette.add(commandDecl.command); | ||
| }); | ||
|
|
||
|
|
||
|
|
||
| it('should have commands appropriately prefixed', function() { | ||
| paletteCmds.forEach(command => { | ||
| expect(commandTitles[command], `command ${command} should be prefixed with 'CodeQL: ', since it is accessible from the command palette`).to.match(/^CodeQL: /); | ||
| }); | ||
|
|
||
| contribContextMenuCmds.forEach(command => { | ||
| expect(commandTitles[command], `command ${command} should be prefixed with 'CodeQL: ', since it is accessible from a context menu in a non-extension-controlled context`).to.match(/^CodeQL: /); | ||
| }); | ||
|
|
||
| scopedCmds.forEach(command => { | ||
| expect(commandTitles[command], `command ${command} should not be prefixed with 'CodeQL: ', since it is accessible from an extension-controlled context`).not.to.match(/^CodeQL: /); | ||
| }); | ||
| }); | ||
|
|
||
| it('should have the right commands accessible from the command palette', function() { | ||
| paletteCmds.forEach(command => { | ||
| expect(disabledInPalette.has(command), `command ${command} should be enabled in the command palette`).to.be.false; | ||
| }); | ||
|
|
||
| // Commands in contribContextMenuCmds may reasonbly be enabled or | ||
| // disabled in the command palette; for example, codeQL.runQuery | ||
| // is available there, since we heuristically figure out which | ||
| // query to run, but codeQL.setCurrentDatabase is not. | ||
|
|
||
| scopedCmds.forEach(command => { | ||
| expect(disabledInPalette.has(command), `command ${command} should be disabled in the command palette`).to.be.true; | ||
| }); | ||
| }); | ||
|
|
||
|
|
||
| }); | ||
|
|
||
|
|
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 had thought the difference between the
codeQLnamespace and thecodeQLDatabasesnamespace was that the latter accepted an existing database as an argument (and so was only applicable in the databases view). Whereas the former could be invoked in any context.I see you're disabling them as global commands, so maybe that's what we want.
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.
Happy to be persuaded about choice of convention, but my intent so far about the
codeQL$FOO.$BARname structure (where$FOOis nonempty) was just about scoping to portions of the interface. Consider for examplecodeQLDatabases.sortByNamewhich does not take a database as an argument, and things likecodeQLQueryHistory.openQuerywhich are relevant to user events taking place in the query history view, but don't imply any particular constraints about the types of those handlers.