CodinGame / monaco-vscode-api

VSCode public API plugged on the monaco editor
MIT License
241 stars 32 forks source link

When hovering on code, nothing happens... #218

Closed adj5672 closed 1 year ago

adj5672 commented 1 year ago

In demo app, when I hover on code, information or error message shown.

image

But, In my app, when I hover on code, nothing happens.. And doesn't send any jsonrpc requests message to language server.

auto complete, auto import, lint and some features are works well..

image

when initialize language server, I receive jsonrpc message like this.

image image

I'm using user services which are

Is there any service override to must add??

Or is it a problem with my language server??

CGNonofr commented 1 year ago

Hard to tell! can you provide a repo that reproduces the issue?

@kaisalmen any idea?

adj5672 commented 1 year ago

Unfortunately, repository is github enterprise's repository for my company so I can't provide.

But, I can provide source codes about monaco editor. (with svelte)

This script code is part of App.svelte about editor.

<script lang="ts">
    import { initServices, MonacoLanguageClient, wasVscodeApiInitialized } from 'monaco-languageclient';
    import getConfigurationServiceOverride, {
        updateUserConfiguration,
    } from '@codingame/monaco-vscode-configuration-service-override';
    import '@codingame/monaco-vscode-java-default-extension';
    import getKeybindingsServiceOverride from '@codingame/monaco-vscode-keybindings-service-override';
    import getThemeServiceOverride from '@codingame/monaco-vscode-theme-service-override';
    import getTextmateServiceOverride from '@codingame/monaco-vscode-textmate-service-override';
    import * as vscode from 'vscode';
    import { Uri } from 'vscode';
    import { toSocket, WebSocketMessageReader, WebSocketMessageWriter } from 'vscode-ws-jsonrpc';
    import type { MessageTransports } from 'vscode-languageclient';
    import { CloseAction, ErrorAction } from 'vscode-languageclient';
    import { theme } from '../const/monaco';
    import { buildWorkerDefinition } from 'monaco-editor-workers';
    import { onMount } from 'svelte';

    let languageClient: MonacoLanguageClient;
    const queryClient = new QueryClient();

    const createWebSocket = (url: string): WebSocket => {
        const webSocket = new WebSocket(url);
        webSocket.onopen = async () => {
            const socket = toSocket(webSocket);
            const reader = new WebSocketMessageReader(socket);
            const writer = new WebSocketMessageWriter(socket);
            languageClient = createLanguageClient({
                reader,
                writer,
            });
            await languageClient.start();
            reader.onClose(() => languageClient.stop());
        };
        return webSocket;
    };

    const createLanguageClient = (transports: MessageTransports): MonacoLanguageClient => {
        return new MonacoLanguageClient({
            name: 'Java Language Client',
            clientOptions: {
                documentSelector: ['java'],
                errorHandler: {
                    error: () => ({ action: ErrorAction.Continue }),
                    closed: () => ({ action: CloseAction.DoNotRestart }),
                },
                synchronize: {
                    fileEvents: [vscode.workspace.createFileSystemWatcher('**')],
                },
            },
            connectionProvider: {
                get: () => {
                    return Promise.resolve(transports);
                },
            },
        });
    };

    onMount(async () => {
        if (!wasVscodeApiInitialized()) {
            // FIXME : μ£Όμ†Œ μˆ˜μ •
            createWebSocket(`ws://localhost:30000/java`);

            buildWorkerDefinition('../node_modules/monaco-editor-workers/dist/workers', import.meta.url, false);

            await initServices({
                userServices: {
                    ...getThemeServiceOverride(),
                    ...getTextmateServiceOverride(),
                    ...getConfigurationServiceOverride(Uri.file('/workspace')),
                    ...getKeybindingsServiceOverride(),
                },
            });

            await updateUserConfiguration(theme);
        }
    });
</script>

And this source code is Monaco Editor component (MonacoEditor.svelte)

<script lang="ts">
    import { onDestroy, onMount } from 'svelte';
    import type * as Monaco from 'monaco-editor/esm/vs/editor/editor.api';
    import ErrorMessage from './ErrorMessage.svelte';
    import { createConfiguredEditor, createModelReference } from 'vscode/monaco';
    import { Uri } from 'vscode';

    let editor: Monaco.editor.IStandaloneCodeEditor;
    let editorContainer: HTMLDivElement;

    export let name: string;
    export let value: string = '';
    export let minHeight: string = '300px';
    export let error: string;
    export let className: string;

    onMount(async () => {
        const modelRef = await createModelReference(Uri.file(`/workspace/src/main/java/com/kakao/harmony/workspace/${className}.java`), value);
        modelRef.object.setLanguageId('java');

        editor = createConfiguredEditor(editorContainer, {
            value,
            model: modelRef.object.textEditorModel,
            automaticLayout: true,
            minimap: {
                enabled: false,
            },
            scrollBeyondLastLine: false,
        });

        editor.getModel().onDidChangeContent(() => {
            if (!editor) return;
            value = editor.getValue();
        });
    });

    onDestroy(() => {
        editor?.dispose();
    });

    $: if (editor && value && value != editor.getValue()) {
        editor.setValue(value);
    }

</script>

<div bind:this={editorContainer} class='monaco-editor' style='min-height: {minHeight}'></div>
<input bind:value={value} name={name} type='hidden' />
<ErrorMessage error={error} />

<style>
    .monaco-editor {
        border: 1px solid #e1e1e1;
        border-radius: 2px;
    }
</style>

Other than this, there is no code related to editor.

And my java language server is based on eclipse jdt ls.

I launch language server with

#!/bin/sh

cd org.eclipse.jdt.ls.product/target/repository || exit

java -Declipse.application=org.eclipse.jdt.ls.core.id1 \
    -Dosgi.bundles.defaultStartLevel=4 \
    -Declipse.product=org.eclipse.jdt.ls.core.product \
    -javaagent:../../../org.eclipse.jdt.ls.tests/lib/lombok-1.18.28.jar \
    -Dlog.level=ALL \
    -Dosgi.dev \
    -Dsocket.stream.debug=true \
    -Xmx1G \
    --add-modules=ALL-SYSTEM \
    --add-opens java.base/java.util=ALL-UNNAMED \
    --add-opens java.base/java.time=ALL-UNNAMED \
    -jar ./plugins/org.eclipse.equinox.launcher_1.6.500.v20230717-2134.jar \
    -configuration ./config_linux \
    -data workspace

I hope the answer helps. πŸ₯²

kaisalmen commented 1 year ago

@adj5672 and @CGNonofr Isn't @codingame/monaco-vscode-languages-service-override missing here?

kaisalmen commented 1 year ago

@adj5672 which version of monaco-languageclient are you using because 6.6.x and monaco-vscode-api always init those services:

adj5672 commented 1 year ago

@kaisalmen version of dependencies are those.

{
    "@codingame/monaco-vscode-configuration-service-override": "^1.82.6",
    "@codingame/monaco-vscode-editor-service-override": "^1.82.6",
    "@codingame/monaco-vscode-files-service-override": "^1.82.6",
    "@codingame/monaco-vscode-java-default-extension": "^1.82.6",
    "@codingame/monaco-vscode-keybindings-service-override": "^1.82.6",
    "@codingame/monaco-vscode-textmate-service-override": "^1.82.6",
    "@codingame/monaco-vscode-theme-defaults-default-extension": "^1.82.3",
    "@codingame/monaco-vscode-theme-service-override": "^1.82.6",
    "@felte/validator-yup": "^1.1.3",
    "@openapitools/openapi-generator-cli": "^2.7.0",
    "axios": "^1.4.0",
    "chalk": "^5.3.0",
    "env-cmd": "^10.1.0",
    "file-loader": "^6.2.0",
    "fs-extra": "^11.1.1",
    "moment": "^2.29.4",
    "monaco-editor": "^0.43.0",
    "monaco-editor-workers": "^0.43.0",
    "monaco-languageclient": "^6.5.3",
    "vscode": "npm:@codingame/monaco-vscode-api@^1.82.6",
    "vscode-json-languageservice": "^5.3.7",
    "vscode-uri": "^3.0.8",
    "vscode-ws-jsonrpc": "^3.0.0",
    "ws": "^8.14.2",
    "yup": "^1.3.2"
  }
kaisalmen commented 1 year ago

Is the data path correct? -data workspace. The client has /workspace I otherwise don't see an obvious error. The version of monaco-langaugeclient has all the services mentioned above pre-configured (6.5.0+ have this).

adj5672 commented 1 year ago

I will check my data path. πŸ€”

Then, no need to add @codingame/monaco-vscode-languages-service-override to user service??

CGNonofr commented 1 year ago

The only point of using the language service override is to be able to use vscode extensions that register new languages

adj5672 commented 1 year ago

@CGNonofr @kaisalmen I think data path may be correct. because if not, there is wellow under line on first line of code.

image

In repository issue with eclipse jdt ls, I found similar problems and it said that occurs in lightweight mode.

here is issue link.

In vscode java reference, Looks like can change mode to standard with java.server.launchMode configuration and I think that it might be a solution. Is it possible with monaco-vscode-api?? Or do I need to fix on my language server??

adj5672 commented 1 year ago

After I update dependencies to latest version with fixed, it works.. πŸ€”

image image image

I think it was dependency compatible issue... thanks..