Search code examples
tokenizevisual-studio-codeextending

VSCode - IntelliSense with custom languages


Hello VS Code Community!

I'm currently extending the VS Code editor with a own / custom language. This is easier as I thought but now I'm getting problems with IntelliSense.

enter image description here


As you can see, VS Code is suggesting me the content of comments and strings and that's the big problem for me.

I'm inexperienced to this and learning by trying ;) I guess it has to do with tokenizer but I have no idea how to specify / exclude comments and variable values.

Normally only declared variables and the given keywords should be suggested

Here the relevant code: (only for learning purposes, no copyright infringement intended)

/*---------------------------------------------------------
 * Copyright (C) Microsoft Corporation. All rights reserved.
 *--------------------------------------------------------*/
/// <reference path="../../declares.d.ts" />
'use strict';
define(["require", "exports", '../sqfDef', 'monaco-testing'], function (require, exports, languageDef, T) {
    var tokenizationSupport = T.createTokenizationSupport(languageDef.language);
    var tokenize = T.createTokenizeFromSupport(tokenizationSupport);
    var assertTokens = T.assertTokens;
    T.module('Syntax Highlighting - SQF');
}

Are there any docs or can someone explain me please how to exclude this from the suggested list?

EDIT: Ok, I realised that you can define object types in the Def.js so defining them in the Tests.js is not necessary. yet my problem persists.


Solution

  • Since there is currently no documentation for writing custom plugins we all gather our information by reverse engineering.

    Take a look at resources\app\plugins\vs.language.typescript\features\suggestSupport.js. In line 10 you find this this.excludeTokens = ['string', 'comment', 'numeric'];. So you need to write your own suggestSupport.js and register it in your languageMain.js.

    You find an example setting it up in resources\app\plugins\vs.language.typescript\typescriptMain.js in line 58:

        var suggestSupport = new SuggestSupport(ctx, client);
        monaco.Modes.SuggestSupport.register(MODE_ID, suggestSupport);
        return Configuration.load(MODE_ID, ctx.configurationService).then(function (config) {
            suggestSupport.setConfiguration(config);
        });