Lsp-mode: js2-mode and derived modes displays lag when typing in large files (300 lines of code or more)

Created on 1 Jan 2019  路  4Comments  路  Source: emacs-lsp/lsp-mode

Describe the bug
When lsp-mode is turned on in js2-mode and derived modes, like rjsx-mode, typing is a painful experience full of lag (1 or 2 seconds or even more depending on how fast you are writing code).

To Reproduce
Steps to reproduce the behavior:

  1. Run emacs -q
  2. Load the configuration bug.txt.
  3. Download and uncompressed the frontend of one of my projects
    fero.zip
  4. visit the file src/components/Invoice/detalle.jsx
  5. finally, go anywhere and hold any key, you should see lag.
  6. extra: put :disabled under (use-package lsp to disabled lsp-mode, then try to reproduce, you will see that typing is smooth again.

Expected behavior
no lag at all like typing in large files with go-mode or python-mode and lsp-mode running.

Which Language Server did you use
this is included with the configuration.

OS
GNU/Linux (Arch)

This happens with lsp-mode version 20181228.819 and only on js2-mode derived modes.

Most helpful comment

The issue is caused by the fact that the typescript language synchronization is full and when you press and hold a key lsp-mode has to send whole file content as a message which is problematic. We should introduce some mechanisim for handling that case or even https://github.com/emacs-lsp/lsp-mode/issues/362

@shackra I would suggest switching to the other javascript language server which seems to be smarter and also supports partial updates(these lines will fix the perf issue).

 (setq lsp-clients-typescript-server "typescript-language-server"
       lsp-clients-typescript-server-args '("--stdio"))

@alanz @MaskRay

All 4 comments

The issue is caused by the fact that the typescript language synchronization is full and when you press and hold a key lsp-mode has to send whole file content as a message which is problematic. We should introduce some mechanisim for handling that case or even https://github.com/emacs-lsp/lsp-mode/issues/362

@shackra I would suggest switching to the other javascript language server which seems to be smarter and also supports partial updates(these lines will fix the perf issue).

 (setq lsp-clients-typescript-server "typescript-language-server"
       lsp-clients-typescript-server-args '("--stdio"))

@alanz @MaskRay

  1. This is apparently a server issue
  2. I don't think grouping texDocument/didChange is necessary
// src/typescript-service.ts
    public async textDocumentDidChange(params: DidChangeTextDocumentParams): Promise<void> {
        const uri = normalizeUri(params.textDocument.uri)
        let text: string | undefined
        for (const change of params.contentChanges) {
            if (change.range || change.rangeLength) {
                throw new Error('incremental updates in textDocument/didChange not supported for file ' + uri)
            }
            text = change.text
        }
        if (!text) {

@shackra I would suggest switching to the other javascript language server which seems to be smarter and also supports partial updates(these lines will fix the perf issue).

 (setq lsp-clients-typescript-server "typescript-language-server"
       lsp-clients-typescript-server-args '("--stdio"))

Ah, indeed @yyoncho, the current typescript server is javascript-typescript-stdio, I will switch as you recommend.

@MaskRay IMO it is not server side issue since full sync is a valid option according to latest LSP spec and we should provide reasonable handling/performance. I am thinking about adding client-side debounce only for full sync text messages.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

axelson picture axelson  路  4Comments

alanz picture alanz  路  6Comments

MaskRay picture MaskRay  路  5Comments

michaelpj picture michaelpj  路  4Comments

yyoncho picture yyoncho  路  5Comments