admin管理员组文章数量:1289558
There are similar questions 1, 2, 3 but the answers described there work only for non-custom languages like C#, JavaScript and TypeScript.
What I want to achieve is to get rid of suggestions based on the previously typed words.
And I also want to keep my custom suggestions added with registerCompletionItemProvider
.
How to do that?
There are similar questions 1, 2, 3 but the answers described there work only for non-custom languages like C#, JavaScript and TypeScript.
What I want to achieve is to get rid of suggestions based on the previously typed words.
And I also want to keep my custom suggestions added with registerCompletionItemProvider
.
How to do that?
Share Improve this question edited Apr 28, 2023 at 16:59 waterstopper asked Apr 28, 2023 at 11:33 waterstopperwaterstopper 5884 silver badges20 bronze badges4 Answers
Reset to default 4Monaco-editor by default provide suggestions based on the previously typed words on the editor. In order to get only the custom added suggestions, you can provide the suggestions through registerCompletionItemProvider and it will override any default suggestions provided by moncao-editor.
Example:
monaco.languages.registerCompletionItemProvider('myCustomLanguage', {
provideCompletionItems: function(model, position) {
const suggestions = [
{
label: 'console',
kind: monaco.languages.CompletionItemKind.Function,
documentation: 'Logs a message to the console.',
insertText: 'console.log()',
},
{
label: 'setTimeout',
kind: monaco.languages.CompletionItemKind.Function,
documentation: 'Executes a function after a specified time interval.',
insertText: 'setTimeout(() => {\n\n}, 1000)',
}
];
return { suggestions: suggestions };
}
});
If you type something now, it will not suggest anything that was earlier typed. On pressing Ctrl+Space, you would see only the above two suggestions("console" & "setTimeOut") on the editor.
I had the same problem, but after some searching and (try and fail) I finally get it.
Just set 'showWords: false' in the 'suggest' configuration, inside the editor creation function:
var editor = monaco.editor.create(document.getElementById("editorContainer"), {
value: jsCode,
language: "typescript", //can use your custom language here
suggest: {
showWords: false
}
});
I have the same problems when I set monaco editor pletion providers return like return { suggetions: [] }
.
This will make pletion menu show some matched word based typed code.
You can set options like this to avoid, related issue Disable autoplete of all used words:
const editor = monaco.editor.create(document.getElementById("editorElement"), {
value: "some codes.",
language: "customLanguage",
// other options: 'currentDocument' | 'matchingDocuments' | 'allDocuments'
wordBasedSuggestions: 'off', // set off means only show pletion items form pletion providers instead of matching words in current code.
});
@Dexxe's answer worked for me as did quickSuggestions: false
:
var editor = monaco.editor.create(document.getElementById("editorContainer"), {
value: jsCode,
language: "typescript", //can use your custom language here
quickSuggestions: false,
});
本文标签: javascriptmonacoeditor remove default autocompletion suggestions for custom languageStack Overflow
版权声明:本文标题:javascript - monaco-editor remove default autocompletion suggestions for custom language - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741431828a2378406.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论