Currently we are integrating Java Language Server to Monaco Editor. There when I am trying to import unknown modules or packages it is not throwing warning or errors.No Error for Unknown Package. Tried using Tokenizer but didn't worked out.

When I am importing any unknown package or error I want error some thing red lines below the package name. Similar to how we will get for typescript. I want to know how to add these type to monaco editor for a new language that we are registering.enter image description here

2

There are 2 answers

0
Mike Lischke On

After you did the semantic validation send diagnostics back, which your extension can use to add such information. For example:

   /**
     * Convert diagnostic information for the given file to show in vscode.
     *
     * @param document The document for which this should happen.
     */
    private processDiagnostic = (document: TextDocument) => {
        const diagnostics = [];
        const entries = this.backend.getDiagnostics(document.fileName);
        for (const entry of entries) {
            const startRow = entry.range.start.row === 0 ? 0 : entry.range.start.row - 1;
            const endRow = entry.range.end.row === 0 ? 0 : entry.range.end.row - 1;
            const range = new Range(startRow, entry.range.start.column, endRow, entry.range.end.column);
            const diagnostic = new Diagnostic(range, entry.message, ExtensionHost.diagnosticTypeMap.get(entry.type));
            diagnostics.push(diagnostic);
        }
        this.diagnosticCollection.set(document.uri, diagnostics);
    };

(from my extension antlr4-vscode).

0
llesha On

First, you need to provide some logic of detecting unknown imported packages.

Then, to underline errors, check corrrsponding page on Monaco editor playground or use this code:

     monaco.editor.setModelMarkers(window.editor.getModel(), 'owner', [
            {
                message: "import not found",
                severity: monaco.MarkerSeverity.Error,
                startLineNumber: 0,
                startColumn: 0,
                endLineNumber: 0,
                endColumn: 2,
            },
        ]);

(change startLineNumber and other range arguments according to highlighted code piece).