A proper way of inserting built-in functions into VS Code extension

北城余情 提交于 2019-12-24 01:00:04

问题


Introduction

I'm currently developing an application based on Bluegiga BLE-112 module. The module is programmable in BGScript scripting language. However, only editor I found, that has some kind of support for BGScript, is Notepad++, which does not suit my needs. Therefore, I started development of my own extension for Visual Studio Code (one available in the extension market is not working). I already went past through colorizer and error parsing, now I'm creating a part with code suggestions.

Main problem

I'd like to have all functions, enumerations and events embedded in the language listed when I'm typing. I found that code snippets could be the way of achieving this. An example of snippet in JSON format that works as I expect looks like below.

"call attclient_indicate_confirm": {
    "prefix": "call attclient_indicate_confirm",
    "body": [
        "call attclient_indicate_confirm(${1:connection})(${2:result})"
    ],
    "description": "Send a acknowledge a received indication from a remote device."
}

call is a keyword indicating, that in this line a function is envoked. When snippet like this is stored in a proper JSON file, everything works fine - I start typing call, VS Code suggests a code snippets and I can use it.

However, creating a code snippet for enumerations looks like an overkill, as enums have nothing variable - they should be inserted as-is.

My question is: are there any ways other than code snippets, that could be implemented inside an Visual Studio Code extension, for creating suggestions of enumerations in BGScript language?


回答1:


Yes, you can register a CompletionItemProvider via registerCompletionItemProvider() (see the languages namespace). This should cover all your use cases, as completion items can also use snippet insertion by making their insertText a SnippetString.

Often this (along with other providers) is implemented through an abstraction layer called the Language Server Protocol instead of using the VSCode API directly, which makes it editor-independent.



来源:https://stackoverflow.com/questions/50761525/a-proper-way-of-inserting-built-in-functions-into-vs-code-extension

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!