TIny-Hacker / language-ti-basic

VS Code language support for (e)Z80 TI-BASIC. Also used by github-linguist
BSD 3-Clause "New" or "Revised" License
14 stars 1 forks source link

Enhancement suggestion: intellisense #1

Open Nanobot567 opened 1 year ago

Nanobot567 commented 1 year ago

You don't have to add this if you don't want to, I just thought it would be a nice addition to the extension :)

TIny-Hacker commented 1 year ago

This is something I've already considered and would like to add in the future. However, I don't know much about how it works and how long it would take.

nineteendo commented 8 months ago

Maybe this could be of help: http://github.com/nineteendo/tmlx/tree/main/Extension This is a fairly simple syntax highlighter with code completion using a language server (doesn't work on temp files). The suggestions are generated like this:

const suggestions = ['black', 'blue', 'color', 'cyan', 'green', 'magenta', 'red', 'white', 'yellow'].map<CompletionItem>(label => {
    return {
        label,
        kind: CompletionItemKind.Constant,
    };
}).concat(['down', 'left', 'right', 'up', 'write'].map(label => {
    return {
        label,
        kind: CompletionItemKind.Function,
    };
})).concat(['else', 'exit', 'goto', 'if', 'while'].map(label => {
    return {
        label,
        kind: CompletionItemKind.Keyword,
    };
}));

Result:

Screenshot 2024-01-28 at 13 42 53

Though we'll have to decide whether we use snippets for functions or not.

nineteendo commented 8 months ago

Also, you should probably remove the lower case prefixes for the snippets:

Screenshot 2024-01-28 at 13 40 44
nineteendo commented 8 months ago

Here is a slightly fancier solution:

const suggestions = [
    {
        kind: CompletionItemKind.Operator,
        items: [
            {
                label: ' or ',
                detail: 'valueA or valueB'
            },
            {
                label: ' xor ',
                detail: 'valueA xor valueB'
            }
        ]
    },
    {
        kind: CompletionItemKind.Function,
        items: [
            {
                label: 'Pt-On(',
                detail: 'Pt-On(x,y[,mark])'
            },
            {
                label: 'Pt-Off(',
                detail: 'Pt-Off(x,y[,mark])'
            }
        ]
    }
].flatMap(group =>
    group.items.map(item => ({
        kind: group.kind,
        label: item.label,
        detail: item.detail
    }))
);
Screenshot 2024-01-28 at 15 26 33

Note that you don't have to provide the detail.

nineteendo commented 8 months ago

Any updates?

TIny-Hacker commented 8 months ago

I'm currently pretty busy right now with other stuff and I'm working on importing / exporting in #4 as well, so this is lower priority. I'll make the change to the snippets but since I'm changing some token formats to match this I feel like it makes sense to wait to work on this until after that is done.

Thanks for providing the examples though, that will certainly come in handy when I get around to it :)