yegappan / lsp

Language Server Protocol (LSP) plugin for Vim9
MIT License
447 stars 43 forks source link

Error with vtsls server. #488

Open adriantrunzo opened 3 months ago

adriantrunzo commented 3 months ago

Description

I am not sure if this problem is with the lsp client or the language server, but I'll try my best to detail what troubleshooting I've tried so far. If the problem is with the language server, I am happy to close this issue and open one there.

I am trying to use the https://github.com/yioneko/vtsls server. The server starts up fine and works well for the first file I open in Vim. When I try to open a second file, however, I receive the following status line text:

Warn: 03/23/24 13:37:40: LSP server (vtsls) exited with status 1

:LspServer debug messages is blank.

:LspServer debug errors shows something like the following:

node:internal/process/promises:289
            triggerUncaughtException(err, true /* fromPromise */);
            ^

_TypeScriptServerError: <semantic> TypeScript Server Error (5.4.3)
Debug Failure. Bad line number. Line: 364, lineStarts.length: 364 , line map is correct? true
Error: Debug Failure. Bad line number. Line: 364, lineStarts.length: 364 , line map is correct? true
    at computePositionOfLineAndCharacter (/Users/adrian.trunzo/dev/ky/node_modules/typescript/lib/tsserver.js:11625:13)
    at TextStorage.lineOffsetToPosition (/Users/adrian.trunzo/dev/ky/node_modules/typescript/lib/tsserver.js:177983:59)
    at ScriptInfo.lineOffsetToPosition (/Users/adrian.trunzo/dev/ky/node_modules/typescript/lib/tsserver.js:178304:29)
    at /Users/adrian.trunzo/dev/ky/node_modules/typescript/lib/tsserver.js:184922:38
    at mapDefinedIterator (/Users/adrian.trunzo/dev/ky/node_modules/typescript/lib/tsserver.js:2690:19)
    at mapDefinedIterator.next (<anonymous>)
    at _ProjectService.applyChangesToFile (/Users/adrian.trunzo/dev/ky/node_modules/typescript/lib/tsserver.js:183722:16)
    at _ProjectService.applyChangesInOpenFiles (/Users/adrian.trunzo/dev/ky/node_modules/typescript/lib/tsserver.js:183693:14)
    at updateOpen (/Users/adrian.trunzo/dev/ky/node_modules/typescript/lib/tsserver.js:184910:29)
    at /Users/adrian.trunzo/dev/ky/node_modules/typescript/lib/tsserver.js:187518:69
    at IpcIOSession.executeWithRequestId (/Users/adrian.trunzo/dev/ky/node_modules/typescript/lib/tsserver.js:187510:14)
    at IpcIOSession.executeCommand (/Users/adrian.trunzo/dev/ky/node_modules/typescript/lib/tsserver.js:187518:29)
    at IpcIOSession.onMessage (/Users/adrian.trunzo/dev/ky/node_modules/typescript/lib/tsserver.js:187560:51)
    at process.<anonymous> (/Users/adrian.trunzo/dev/ky/node_modules/typescript/lib/tsserver.js:189169:14)
    at process.emit (node:events:518:28)
    at emit (node:internal/child_process:951:14)
    at process.processTicksAndRejections (node:internal/process/task_queues:83:21)
    at _TypeScriptServerError.create (/Users/adrian.trunzo/Library/Application Support/fnm/node-versions/v20.11.0/installation/lib/node_modules/@vtsls/language-server/node_modules/@vtsls/language-service/dist/index.js:5198:16)
    at _SingleTsServer.dispatchResponse (/Users/adrian.trunzo/Library/Application Support/fnm/node-versions/v20.11.0/installation/lib/node_modules/@vtsls/language-server/node_modules/@vtsls/language-service/dist/index.js:5382:50)
    at _SingleTsServer.dispatchMessage (/Users/adrian.trunzo/Library/Application Support/fnm/node-versions/v20.11.0/installation/lib/node_modules/@vtsls/language-server/node_modules/@vtsls/language-service/dist/index.js:5324:22)
    at ChildProcess.<anonymous> (/Users/adrian.trunzo/Library/Application Support/fnm/node-versions/v20.11.0/installation/lib/node_modules/@vtsls/language-server/node_modules/@vtsls/language-service/dist/index.js:5294:16)
    at ChildProcess.emit (node:events:518:28)
    at emit (node:internal/child_process:951:14)
    at process.processTicksAndRejections (node:internal/process/task_queues:83:21) {
  serverId: 'semantic',
  version: TypeScriptVersion {
    source: 'node-modules',
    path: '/Users/adrian.trunzo/dev/ky/node_modules/typescript/lib/tsserver.js',
    apiVersion: _API {
      displayName: '5.4.3',
      version: '5.4.3',
      fullVersionString: '5.4.3'
    },
    _pathLabel: 'node_modules/typescript/lib'
  },
  response: {
    seq: 0,
    type: 'response',
    command: 'updateOpen',
    request_seq: 5,
    success: false,
    message: 'Error processing request. Debug Failure. Bad line number. Line: 364, lineStarts.length: 364 , line map is correct? true\n' +
      'Error: Debug Failure. Bad line number. Line: 364, lineStarts.length: 364 , line map is correct? true\n' +
      '    at computePositionOfLineAndCharacter (/Users/adrian.trunzo/dev/ky/node_modules/typescript/lib/tsserver.js:11625:13)\n' +
      '    at TextStorage.lineOffsetToPosition (/Users/adrian.trunzo/dev/ky/node_modules/typescript/lib/tsserver.js:177983:59)\n' +
      '    at ScriptInfo.lineOffsetToPosition (/Users/adrian.trunzo/dev/ky/node_modules/typescript/lib/tsserver.js:178304:29)\n' +
      '    at /Users/adrian.trunzo/dev/ky/node_modules/typescript/lib/tsserver.js:184922:38\n' +
      '    at mapDefinedIterator (/Users/adrian.trunzo/dev/ky/node_modules/typescript/lib/tsserver.js:2690:19)\n' +
      '    at mapDefinedIterator.next (<anonymous>)\n' +
      '    at _ProjectService.applyChangesToFile (/Users/adrian.trunzo/dev/ky/node_modules/typescript/lib/tsserver.js:183722:16)\n' +
      '    at _ProjectService.applyChangesInOpenFiles (/Users/adrian.trunzo/dev/ky/node_modules/typescript/lib/tsserver.js:183693:14)\n' +
      '    at updateOpen (/Users/adrian.trunzo/dev/ky/node_modules/typescript/lib/tsserver.js:184910:29)\n' +
      '    at /Users/adrian.trunzo/dev/ky/node_modules/typescript/lib/tsserver.js:187518:69\n' +
      '    at IpcIOSession.executeWithRequestId (/Users/adrian.trunzo/dev/ky/node_modules/typescript/lib/tsserver.js:187510:14)\n' +
      '    at IpcIOSession.executeCommand (/Users/adrian.trunzo/dev/ky/node_modules/typescript/lib/tsserver.js:187518:29)\n' +
      '    at IpcIOSession.onMessage (/Users/adrian.trunzo/dev/ky/node_modules/typescript/lib/tsserver.js:187560:51)\n' +
      '    at process.<anonymous> (/Users/adrian.trunzo/dev/ky/node_modules/typescript/lib/tsserver.js:189169:14)\n' +
      '    at process.emit (node:events:518:28)\n' +
      '    at emit (node:internal/child_process:951:14)\n' +
      '    at process.processTicksAndRejections (node:internal/process/task_queues:83:21)',
    _serverType: 'semantic'
  },
  serverMessage: 'Debug Failure. Bad line number. Line: 364, lineStarts.length: 364 , line map is correct? true',
  serverStack: 'Error: Debug Failure. Bad line number. Line: 364, lineStarts.length: 364 , line map is correct? true\n' +
    '    at computePositionOfLineAndCharacter (/Users/adrian.trunzo/dev/ky/node_modules/typescript/lib/tsserver.js:11625:13)\n' +
    '    at TextStorage.lineOffsetToPosition (/Users/adrian.trunzo/dev/ky/node_modules/typescript/lib/tsserver.js:177983:59)\n' +
    '    at ScriptInfo.lineOffsetToPosition (/Users/adrian.trunzo/dev/ky/node_modules/typescript/lib/tsserver.js:178304:29)\n' +
    '    at /Users/adrian.trunzo/dev/ky/node_modules/typescript/lib/tsserver.js:184922:38\n' +
    '    at mapDefinedIterator (/Users/adrian.trunzo/dev/ky/node_modules/typescript/lib/tsserver.js:2690:19)\n' +
    '    at mapDefinedIterator.next (<anonymous>)\n' +
    '    at _ProjectService.applyChangesToFile (/Users/adrian.trunzo/dev/ky/node_modules/typescript/lib/tsserver.js:183722:16)\n' +
    '    at _ProjectService.applyChangesInOpenFiles (/Users/adrian.trunzo/dev/ky/node_modules/typescript/lib/tsserver.js:183693:14)\n' +
    '    at updateOpen (/Users/adrian.trunzo/dev/ky/node_modules/typescript/lib/tsserver.js:184910:29)\n' +
    '    at /Users/adrian.trunzo/dev/ky/node_modules/typescript/lib/tsserver.js:187518:69\n' +
    '    at IpcIOSession.executeWithRequestId (/Users/adrian.trunzo/dev/ky/node_modules/typescript/lib/tsserver.js:187510:14)\n' +
    '    at IpcIOSession.executeCommand (/Users/adrian.trunzo/dev/ky/node_modules/typescript/lib/tsserver.js:187518:29)\n' +
    '    at IpcIOSession.onMessage (/Users/adrian.trunzo/dev/ky/node_modules/typescript/lib/tsserver.js:187560:51)\n' +
    '    at process.<anonymous> (/Users/adrian.trunzo/dev/ky/node_modules/typescript/lib/tsserver.js:189169:14)\n' +
    '    at process.emit (node:events:518:28)\n' +
    '    at emit (node:internal/child_process:951:14)\n' +
    '    at process.processTicksAndRejections (node:internal/process/task_queues:83:21)',
  sanitizedStack: 'tsserver.js:11625:13\n' +
    'tsserver.js:177983:59\n' +
    'tsserver.js:178304:29\n' +
    'tsserver.js:184922:38\n' +
    'tsserver.js:2690:19\n' +
    'tsserver.js:183722:16\n' +
    'tsserver.js:183693:14\n' +
    'tsserver.js:184910:29\n' +
    'tsserver.js:187518:69\n' +
    'tsserver.js:187510:14\n' +
    'tsserver.js:187518:29\n' +
    'tsserver.js:187560:51\n' +
    'tsserver.js:189169:14\n'
}

Node.js v20.11.0

The TS process is complaining about a bad line number and that line number (364 in this example) is always one more than the actual line count of the file.

Expected Behavior

No error when opening a second file.

Actual Behavior

The language server crashes with an error originating in the TS process.

Steps to Reproduce

  1. Install Node >= 16
  2. npm install -g @vtsls/language-server
  3. Configure the server in vim configuration like:
    
    packadd lsp
    let servers = [#{
    \ filetype: [
    \   'javascript', 'javascriptreact', 'typescript', 'typescriptreact'
    \ ],
    \ path: 'vtsls',
    \ args: ['--stdio'],
    \ debug: v:true,
    \ features: #{ documentFormatting: v:false },
    \ workspaceConfig: #{
    \   vtsls: #{
    \     autoUseWorkspaceTsdk: v:true,
    \   }
    \ },
    \ }]

call LspAddServer(servers)


4. `git clone https://github.com/sindresorhus/ky.git` (I've just chosen a random public project for this example. I've encountered the issue in every project I tried.)
5. `cd ky`
6. `vim`
7. `:e source/index.ts`
8. `:e source/core/Ky.ts`

# Discussion

I tried to figure out if the lsp client is sending a bad line number to the server, but I couldn't see any sent messages in the debug logs. As I mentioned above, `:LspServer debug messages` contains no mention of the second file. If I toggle the debug off and back on between steps 7 and 8 the messages log is blank after opening the second file.

I am happy to keep troubleshooting, but I am not well versed in the protocol and I don't know what to expect in the log files from the client. Should I see some request that includes the line number when I open files in Vim?