-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
Semantic highlighting does not appear to work (due to theming) #1833
Comments
The standalone APIs are all hooked up, but I believe there is no theming implemented for the standalone editor. So those semantic tokens get looked up, no theming returns, so the semantic tokens are dropped. @aeschli |
@rcjsuen You could try to do this by providing a custom theme service, (with the first created editor) e.g. monaco.editor.create(element, opts, { themeService: yourCustomImplementation }); You would then need to implement export interface IThemeService {
_serviceBrand: undefined;
getTheme(): ITheme;
readonly onThemeChange: Event<ITheme>;
getIconTheme(): IIconTheme;
readonly onIconThemeChange: Event<IIconTheme>;
} |
@alexdima I tried a simpler approach but nothing seems to be working. Since monaco.languages.register({
id: 'new'
});
monaco.languages.registerDocumentSemanticTokensProvider('new', {
getLegend: () => {
return {
tokenModifiers: [],
tokenTypes: [
"keyword"
]
}
},
provideDocumentSemanticTokens: () => {
console.log("provideDocumentSemanticTokens");
debugger;
return {
data: [
0, 0, 4, 0, 0
]
}
},
releaseDocumentSemanticTokens: () => {
}
});
const editor = monaco.editor.create(document.getElementById("container"), {
value: "12345678",
language: "new"
});
const ts = editor._themeService;
const t = ts._theme;
t.getTokenStyleMetadata = (type, modifiers) => {
console.log(type);
console.log(modifiers);
return undefined;
}; |
@rcjsuen This is indeed a mess, and sorry about that. Semantic highlighting has shipped turned off by default. Due to it being a global setting (not an editor instance setting), it was also overlooked in monaco.d.ts typings, where it would need to be added manually... The way to enable it is to use: const editor = monaco.editor.create(document.getElementById("container"), {
value: "12345678",
language: "new",
'semanticHighlighting.enabled': true
}); The weird dot keyname must be used due to some more trouble with object-like global settings which are not picked up, so using A full working sample: monaco.languages.register({
id: 'new'
});
monaco.languages.registerDocumentSemanticTokensProvider('new', {
getLegend: () => {
return {
tokenModifiers: [],
tokenTypes: [
"keyword"
]
}
},
provideDocumentSemanticTokens: () => {
return {
data: [
0, 0, 4, 0, 0
]
}
},
releaseDocumentSemanticTokens: () => {
}
});
const editor = monaco.editor.create(document.getElementById("container"), {
value: "12345678",
language: "new",
'semanticHighlighting.enabled': true
});
const t = editor._themeService._theme;
t.getTokenStyleMetadata = (type, modifiers) => {
if (type === 'keyword') {
return {
foreground: 5, // color id 5
bold: true,
underline: true,
italic: true
};
}
}; |
@alexdima Thank you very much for your fully working sample! I adapted your model to my code and found that the use of a model seems to break the semantic highlighting. :( Please see the attached playground sample. If you toggle monaco.languages.register({
id: 'new'
});
monaco.languages.registerDocumentSemanticTokensProvider('new', {
getLegend: () => {
return {
tokenModifiers: [],
tokenTypes: [
"keyword"
]
}
},
provideDocumentSemanticTokens: () => {
return {
data: [
0, 0, 4, 0, 0
]
}
},
releaseDocumentSemanticTokens: () => {
}
});
let works = false;
let options = {
'semanticHighlighting.enabled': true
};
if (works) {
options["value"] = "12345678";
options["language"] = "new";
} else {
const model = monaco.editor.createModel("12345678", "new");
options["model"] = model;
}
editor = monaco.editor.create(document.getElementById("container"), options);
const t = editor._themeService._theme;
t.getTokenStyleMetadata = (type, modifiers) => {
if (type === 'keyword') {
return {
foreground: 13, // color id 13
bold: false,
underline: false,
italic: false
};
}
}; |
Other than the bug above, I was able to get something off the ground so it's now published online. #escape=\
FROM node:alpine AS build
ARG aaa
RUN $aaa
#comment
HEALTHCHECK --interval=30s --timeout=30s CMD echo "var"
COPY lib /docker-langserver/lib
COPY bin /docker-langserver/bin
COPY package.json /docker-langserver/package.json
WORKDIR /docker-langserver/
RUN npm install --production && \
chmod +x /docker-langserver/bin/docker-langserver
ENTRYPOINT [ "/docker-langserver/bin/docker-langserver" ] |
@rcjsuen Yes, there is a problem again rooted in the default value of |
@alexdima Makes sense to me. Thank you for your information and all your help! |
@rcjsuen I've pushed a fix for the case you hit, so now the simple configuration service also emits a change event correctly. |
@aeschli @alexdima How can I help move this forward? Though I realize it's probably too late for the next release given the timeline noted in microsoft/vscode#90371. |
@aeschli @alexdima Now that microsoft/vscode#86415 has been finalized, can this be prioritized for April? |
Is there any update on this topic @alexdima? (Related question on Stackoverflow.) |
Yes. AFAIK this works somewhat by using theme rules, but the theme rules cannot select semantic token modifiers, they can only target semantic token types and partially modifiers. So this issue is not 100% done. There is an example of theming working with the semantic token types at https://microsoft.github.io/monaco-editor/playground.html#extending-language-services-semantic-tokens-provider-example |
I see. Thanks for the update @alexdima! Is there some way to (easily) make the respective
Are there some plans to address this? |
Would be nice! |
releaseDocumentSemanticTokens
in particular is not clear to me what I should be doing there.The text was updated successfully, but these errors were encountered: