monaco-languageclient: Typescript incorrect type highlighting

Hey,

I recently started using this library for web code editor side project. I have copied over wrapperTs, but cannot get Typescript errors to be highlighted. Is there some setting that has to be checked?

This is my monaco.ts that is basically a copy of wrapperTs.ts.

import * as monaco from 'monaco-editor';
import getKeybindingsServiceOverride from '@codingame/monaco-vscode-keybindings-service-override';
import '@codingame/monaco-vscode-theme-defaults-default-extension';
import '@codingame/monaco-vscode-typescript-basics-default-extension';
import '@codingame/monaco-vscode-typescript-language-features-default-extension';
import { CodePlusUri, MonacoEditorLanguageClientWrapper, UserConfig } from 'monaco-editor-wrapper';
import { useWorkerFactory } from 'monaco-editor-wrapper/workerFactory';

export const configureMonacoWorkers = () => {
    useWorkerFactory({
        ignoreMapping: true,
        workerLoaders: {
            editorWorkerService: () => new Worker(new URL('monaco-editor/esm/vs/editor/editor.worker.js', import.meta.url), { type: 'module' })
        }
    });
};

export const runTsWrapper = async () => {
    const codeUri = '/workspace/hello.ts';
    const code = `function sayHello(): string {
    return "Hello";
};`;

    const codeOriginalUri = '/workspace/goodbye.ts';
    const codeOriginal = `function sayGoodbye(): string {
    return "Goodbye";
};`;

    const monacoEditorConfig = {
        glyphMargin: true,
        guides: {
            bracketPairs: true
        },
        lightbulb: {
            enabled: monaco.editor.ShowLightbulbIconMode.On
        },
        theme: 'vs-light'
    };

    const monacoDiffEditorConfig = {
        ...monacoEditorConfig,
        renderSideBySide: false
    };

    const userConfig: UserConfig = {
        wrapperConfig: {
            serviceConfig: {
                userServices: {
                    ...getKeybindingsServiceOverride()
                },

                enableExtHostWorker: true,
                debugLogging: true
            },
            editorAppConfig: {
                $type: 'extended',
                codeResources: {
                    main: {
                        text: code,
                        uri: codeUri,
                        fileExt: 'ts'
                    },
                    original: {
                        text: codeOriginal,
                        uri: codeOriginalUri,
                        fileExt: 'ts'
                    }
                },
                useDiffEditor: false,
                editorOptions: monacoEditorConfig,
                diffEditorOptions: monacoDiffEditorConfig
            }
        }
    };

What should I include in the code to get errors highlighted. For example, this should show an error:

console.abc();

Property 'abc' does not exist on type 'Console'. Did you mean 'log'?(2551)

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 28

Most upvoted comments

You were faster than me 😃 that what I was going to answer, not really sure why they disable it by default…

@KornelijusS you need to use the newest version. 8.6.0 and 5.3.0 are compatible with v6. See if npm list shows mismatching monaco-vscode-api versions.

    "monaco-editor-wrapper": "^5.2.0",
    "monaco-languageclient": "^8.5.0",

Hey, found a solution. It seems that this options must be enabled in userConfig to work: "typescript.tsserver.web.projectWideIntellisense.suppressSemanticErrors": false. Thanks for pointing me on the right track. I hope I didn’t take too much of your time