question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Intellisense tips like webstorm

See original GitHub issue

I don’t know if Intellisense already exists, but I miss how the webstorm works. He gives tips to simplify / improve the code.

See the example below, ignore the simplicity, because I just want to show the tip that the webstorm with Intellisense brings.

Writing roughly, by a junior developer: (javascript/typescript)

const t = 'teste';
const testFn = () => {
    if (t && t === 'teste') {
        return true;
    } else {
        return false;
    }
};

webstorm tip edit-1

after the tip the webstorm gave: edit-2

how do you activate something like that in monaco? or if you don’t have it, you can create a custom configuration to do this and how I would configure it and get the result suggested above by the webstorm.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:10 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
rcjsuencommented, Apr 3, 2020

@GlauberF You’ll need to a) create some model markers and b) create the code action and its corresponding edit. Run this code in the Monaco Editor Playground to see a sample.

monaco.languages.register({ id: 'demoLanguage' });
const uri = monaco.Uri.parse("inmemory://test");
monaco.languages.registerCodeActionProvider("demoLanguage", {
    provideCodeActions() {
        return {
            actions: [
                {
                    title: "lowercase",
                    edit: {
                        edits: [
                            {
                                resource: uri,
                                edit: {
                                    text: "abcde",
                                    range: {
                                        startLineNumber: 1,
                                        startColumn: 1,
                                        endLineNumber: 1,
                                        endColumn: 6,
                                    }
                                }
                            }
                        ]
                    }
                }
            ],
            dispose: () => {}
        }
    }
});

const model = monaco.editor.createModel("ABCDE", "demoLanguage", uri);
editor = monaco.editor.create(document.getElementById("container"), {
    model: model,
    lightbulb: {
        enabled: true
    },
});
monaco.editor.setModelMarkers(model, "owner", [
    {
        message: "Sample error message",
        severity: monaco.MarkerSeverity.Error,
        startLineNumber: 1,
        startColumn: 1,
        endLineNumber: 1,
        endColumn: 1,
    }
]);
0reactions
alexdimacommented, Sep 4, 2020

@GlauberF You need to implement this by yourself. You need to find an AST parser, you can use the one from the TypeScript project, or get another one and then you would need to walk the AST and search for this pattern x && x=='y'. This is something that you need to figure out and is not related to the Monaco Editor. @rcjsuen has done a fantastic job of showing you how to plug into the editor your semantic analysis, once you have implemented it.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Code completion | WebStorm Documentation - JetBrains
Press Ctrl+Alt+S to open the IDE settings and select Editor | General | Code Completion. · Select the Show suggestions as you type...
Read more >
How to Switch from WebStorm to VS Code
How To Switch from WebStorm to VS Code. In this article, I'm not going to compare WebStorm with VS Code or share the...
Read more >
Does WebStorm have intellisense like VSCode?
Does WebStorm have intellisense of function like VSCode? Yes, it does. Among the features of WebStorm you can find that.
Read more >
VSCode still lags behind Webstorm in terms of intellisense ...
It feels like VSCode is a first class TypeScript/React citizen while WebStorm is the old, cheap Java variant supposed to work on every...
Read more >
VSCode vs WebStorm - Robert Cooper
One thing I like about WebStorm is that it gives you hints related to any duplicated code it finds in your project which...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found