-
Notifications
You must be signed in to change notification settings - Fork 446
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
Support semantic tokens #1393
Support semantic tokens #1393
Conversation
@Eskibear can you please fix the conflict? |
src/semanticTokenProvider.ts
Outdated
}); | ||
} | ||
|
||
function isSemanticHTokensEnabled(): boolean { |
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.
isSemanticHighlightingEnabled
src/extension.ts
Outdated
@@ -517,6 +518,9 @@ export function activate(context: ExtensionContext): Promise<ExtensionAPI> { | |||
context.subscriptions.push(commands.registerCommand(Commands.CLEAN_WORKSPACE, () => cleanWorkspace(workspacePath))); | |||
|
|||
context.subscriptions.push(onConfigurationChange(languageClient, context)); | |||
|
|||
// temporary implementation Semantic Highlighting before it is part of LSP | |||
registerSemanticTokensProvider(context); |
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 too early, the server is not started yet, so causes:
rejected promise not handled within 1 second: Error: command 'java.execute.workspaceCommand' not found
extensionHostProcess.js:920
stack trace: Error: command 'java.execute.workspaceCommand' not found
at e._tryExecuteCommand (file:///Applications/Visual Studio Code - Insiders.app/Contents/Resources/app/out/vs/workbench/workbench.desktop.main.js:3621:469)
at file:///Applications/Visual Studio Code - Insiders.app/Contents/Resources/app/out/vs/workbench/workbench.desktop.main.js:3621:350
at processTicksAndRejections (internal/process/task_queues.js:85:5)
extensionHostProcess.js:920
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 bad, it should be put in the callback of languageClient.onReady()
.
@Eskibear So I can see the tokens with the scope inspector, but, from a user standpoint, it makes no difference, since no colors are assigned to those tokens. Do we need to modify the Java grammar upstream or is this something additional we need to provide? |
import { Commands } from './commands'; | ||
import { getJavaConfiguration } from './utils'; | ||
|
||
export function registerSemanticTokensProvider(context: vscode.ExtensionContext) { |
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.
if vscode.languages.registerDocumentSemanticTokensProvider is not supported, we should bail (else it'll break in Theia)
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 see, then I should check if the API exists first, i.e.:
if (languages.registerDocumentSemanticTokensProvider) {
// ...
}
vscode maps token classification to textmate scopes, and then the styles are assigned.
We just provide token According to this doc about token styling, users can add custom rules before it's supported by the theme. e.g. "editor.tokenColorCustomizationsExperimental": {
"*.static":{
"fontStyle": "italic"
},
"*.final":{
"fontStyle": "bold"
},
"*.deprecated": {
"fontStyle": "underline"
},
} Of course we are able to provide default value of this setting. If provided, ok the users immediately see the difference and know the feature, which is good. The only concern is, it looks a little out of our scope (and might overwrite uesr's theme), and I'm not sure whether we should do that. What do you think? |
Signed-off-by: Yan Zhang <[email protected]>
Signed-off-by: Yan Zhang <[email protected]>
If we could provide default semantic highlighting values, that can be disabled with a pref key, that would allow users to benefit from the feature right now and disable our defaults once a theme supports it |
BTW vscode shows deprecated code with strikethrough already, so only static and final would need to be added |
That makes sense. However, I just tried directly adding above style into Let me investigate a liitle bit to see if we can embed a simple theme here. |
@Eskibear I don't know if it's possible but if we could at least just document how to do it using
|
I'm ok with just documenting it, adding vscode's wiki about Semantic-Highlighting-Overview#token-styling as reference. How about adding a section in README? Or below description of pref key |
+1 for a section in the README. |
@Eskibear there's still room for improvement ;-) |
Yes, I've also seen the same case occasionally, especially when you change the setting Well it's a good thing that developers are trying it and creating issues for vscode. Now I think it's good to just document how to customize the style. Developers who want to try it could dogfood and help us find potential issues, while others won't be blocked in the meantime. |
Signed-off-by: Yan Zhang <[email protected]>
Thanks @Eskibear! |
depends on eclipse-jdtls/eclipse.jdt.ls#1408
To enable Semantic Highlighting, this PR registers a semantic tokens provider, which actually forward the request to the language server via a delegate command. After semantic highlighting becomes part of LSP, the provider and related delegate commands should be removed, and LS should respond directly to corresponding LSP requests