yioneko / vtsls

LSP wrapper for typescript extension of vscode
Other
432 stars 6 forks source link

RangeError: Incorrect locale information provided #185

Closed PHSix closed 1 month ago

PHSix commented 1 month ago

HI! I was trying to migrate vtsls to coc.nvim to use as a plugin to replace coc-tsserver (because it was making me lag in large projects) when I had some problems with the migration, it was getting information from typescript but I didn't know how to fix it, here is the log of it:

2024-07-14T17:03:50.475 ERROR (pid:58182) [server] - unhandledRejection  Promise {
  <rejected> _ResponseError: Request textDocument/completion failed with message: <semantic> TypeScript Server Error (5.5.2)
  Incorrect locale information provided
  RangeError: Incorrect locale information provided
      at new Collator (<anonymous>)
      at createIntlCollatorStringComparer (/home/ph/.npm-packages/lib/node_modules/@vtsls/language-server/node_modules/typescript/lib/typescript.js:3621:22)
      at compareStringsCaseSensitiveUI (/home/ph/.npm-packages/lib/node_modules/@vtsls/language-server/node_modules/typescript/lib/typescript.js:3637:74)
      at compareCompletionEntries (/home/ph/.npm-packages/lib/node_modules/@vtsls/language-server/node_modules/typescript/lib/typescript.js:162554:16)
      at binarySearchKey (/home/ph/.npm-packages/lib/node_modules/@vtsls/language-server/node_modules/typescript/lib/typescript.js:3105:13)
      at binarySearch (/home/ph/.npm-packages/lib/node_modules/@vtsls/language-server/node_modules/typescript/lib/typescript.js:3094:10)
      at insertSorted (/home/ph/.npm-packages/lib/node_modules/@vtsls/language-server/node_modules/typescript/lib/typescript.js:2883:23)
      at getCompletionEntriesFromSymbols (/home/ph/.npm-packages/lib/node_modules/@vtsls/language-server/node_modules/typescript/lib/typescript.js:163947:5)
      at completionInfoFromData (/home/ph/.npm-packages/lib/node_modules/@vtsls/language-server/node_modules/typescript/lib/typescript.js:162967:23)
      at Object.getCompletionsAtPosition (/home/ph/.npm-packages/lib/node_modules/@vtsls/language-server/node_modules/typescript/lib/typescript.js:162513:24)
      at Object.getCompletionsAtPosition2 [as getCompletionsAtPosition] (/home/ph/.npm-packages/lib/node_modules/@vtsls/language-server/node_modules/typescript/lib/typescript.js:149101:35)
      at IpcIOSession.getCompletions (/home/ph/.npm-packages/lib/node_modules/@vtsls/language-server/node_modules/typescript/lib/typescript.js:190599:54)
      at completionInfo (/home/ph/.npm-packages/lib/node_modules/@vtsls/language-server/node_modules/typescript/lib/typescript.js:188978:43)
      at /home/ph/.npm-packages/lib/node_modules/@vtsls/language-server/node_modules/typescript/lib/typescript.js:191397:69
      at IpcIOSession.executeWithRequestId (/home/ph/.npm-packages/lib/node_modules/@vtsls/language-server/node_modules/typescript/lib/typescript.js:191389:14)
      at IpcIOSession.executeCommand (/home/ph/.npm-packages/lib/node_modules/@vtsls/language-server/node_modules/typescript/lib/typescript.js:191397:29)
      at IpcIOSession.onMessage (/home/ph/.npm-packages/lib/node_modules/@vtsls/language-server/node_modules/typescript/lib/typescript.js:191439:51)
      at process.<anonymous> (/home/ph/.npm-packages/lib/node_modules/@vtsls/language-server/node_modules/typescript/lib/tsserver.js:523:14)
      at process.emit (node:events:519:28)
      at emit (node:internal/child_process:951:14)
      at process.processTicksAndRejections (node:internal/process/task_queues:83:21)
      at handleResponse (/home/ph/.local/share/nvim/lazy/coc.nvim/build/index.js:20190:40)
      at handleMessage (/home/ph/.local/share/nvim/lazy/coc.nvim/build/index.js:20000:11)
      at processMessageQueue (/home/ph/.local/share/nvim/lazy/coc.nvim/build/index.js:20015:13)
      at Immediate.<anonymous> (/home/ph/.local/share/nvim/lazy/coc.nvim/build/index.js:19991:11)
      at process.processImmediate (node:internal/timers:478:21) {
    code: -32603,
    data: undefined
  }
} _ResponseError: Request textDocument/completion failed with message: <semantic> TypeScript Server Error (5.5.2)
Incorrect locale information provided
RangeError: Incorrect locale information provided
    at new Collator (<anonymous>)
    at createIntlCollatorStringComparer (/home/ph/.npm-packages/lib/node_modules/@vtsls/language-server/node_modules/typescript/lib/typescript.js:3621:22)
    at compareStringsCaseSensitiveUI (/home/ph/.npm-packages/lib/node_modules/@vtsls/language-server/node_modules/typescript/lib/typescript.js:3637:74)
    at compareCompletionEntries (/home/ph/.npm-packages/lib/node_modules/@vtsls/language-server/node_modules/typescript/lib/typescript.js:162554:16)
    at binarySearchKey (/home/ph/.npm-packages/lib/node_modules/@vtsls/language-server/node_modules/typescript/lib/typescript.js:3105:13)
    at binarySearch (/home/ph/.npm-packages/lib/node_modules/@vtsls/language-server/node_modules/typescript/lib/typescript.js:3094:10)
    at insertSorted (/home/ph/.npm-packages/lib/node_modules/@vtsls/language-server/node_modules/typescript/lib/typescript.js:2883:23)
    at getCompletionEntriesFromSymbols (/home/ph/.npm-packages/lib/node_modules/@vtsls/language-server/node_modules/typescript/lib/typescript.js:163947:5)
    at completionInfoFromData (/home/ph/.npm-packages/lib/node_modules/@vtsls/language-server/node_modules/typescript/lib/typescript.js:162967:23)
    at Object.getCompletionsAtPosition (/home/ph/.npm-packages/lib/node_modules/@vtsls/language-server/node_modules/typescript/lib/typescript.js:162513:24)
    at Object.getCompletionsAtPosition2 [as getCompletionsAtPosition] (/home/ph/.npm-packages/lib/node_modules/@vtsls/language-server/node_modules/typescript/lib/typescript.js:149101:35)
    at IpcIOSession.getCompletions (/home/ph/.npm-packages/lib/node_modules/@vtsls/language-server/node_modules/typescript/lib/typescript.js:190599:54)
    at completionInfo (/home/ph/.npm-packages/lib/node_modules/@vtsls/language-server/node_modules/typescript/lib/typescript.js:188978:43)
    at /home/ph/.npm-packages/lib/node_modules/@vtsls/language-server/node_modules/typescript/lib/typescript.js:191397:69
    at IpcIOSession.executeWithRequestId (/home/ph/.npm-packages/lib/node_modules/@vtsls/language-server/node_modules/typescript/lib/typescript.js:191389:14)
    at IpcIOSession.executeCommand (/home/ph/.npm-packages/lib/node_modules/@vtsls/language-server/node_modules/typescript/lib/typescript.js:191397:29)
    at IpcIOSession.onMessage (/home/ph/.npm-packages/lib/node_modules/@vtsls/language-server/node_modules/typescript/lib/typescript.js:191439:51)
    at process.<anonymous> (/home/ph/.npm-packages/lib/node_modules/@vtsls/language-server/node_modules/typescript/lib/tsserver.js:523:14)
    at process.emit (node:events:519:28)
    at emit (node:internal/child_process:951:14)
    at process.processTicksAndRejections (node:internal/process/task_queues:83:21)
    at handleResponse (/home/ph/.local/share/nvim/lazy/coc.nvim/build/index.js:20190:40)
    at handleMessage (/home/ph/.local/share/nvim/lazy/coc.nvim/build/index.js:20000:11)
    at processMessageQueue (/home/ph/.local/share/nvim/lazy/coc.nvim/build/index.js:20015:13)
    at Immediate.<anonymous> (/home/ph/.local/share/nvim/lazy/coc.nvim/build/index.js:19991:11)
    at process.processImmediate (node:internal/timers:478:21) {
  code: -32603,
  data: undefined
}

Here is my extension source code:

import { LanguageClient, LanguageClientOptions, services, ServerOptions,  workspace, executable, window, commands, ExtensionContext } from 'coc.nvim';

const supportFiletypes = [
    'javascript',
    'javascript.jsx',
    'javascriptreact',
    'typescript',
    'typescriptreact',
    'typescript.tsx',
];

function getConfig() {
  return workspace.getConfiguration('typescript')
}

export async function activate(ctx: ExtensionContext): Promise<void> {
  if (!executable('vtsls')) {
    return
  }

  const outputChannel = window.createOutputChannel('typescript')

  const serverOptions: ServerOptions = {
    command: 'vtsls',
        args: ['--stdio'],
  };

  const clientOptions: LanguageClientOptions = {
    documentSelector: supportFiletypes.map(ft => ({language: ft, scheme: 'file'})),
    outputChannel,
    initializationOptions: getConfig(),
    middleware: {
      provideDocumentSymbols(document, token, next) {
        return []
      },
      provideDocumentSemanticTokens(document, token, next) {
        return null
      },
      provideCompletionItem(document, position, context, token, next) {
                const result = next(document, position, context, token)
                if (result instanceof Promise) {
                    result.then(ctx.logger.info)
                }
        return []
      },
    },
    synchronize: {
      fileEvents: workspace.createFileSystemWatcher('{**/*.js,**/*.ts,**/*.jsx,**/*.tsx,**/tsconfig.json,**/jsconfig.json}', false, false, false),
    },
  };

  const client = new LanguageClient('typescript', 'Typescript', serverOptions, clientOptions);
  ctx.subscriptions.push(services.registerLanguageClient(client));

  commands.registerCommand('typescript.openLog', () => outputChannel.show())
}

And I've found the same problem when dealing with documentSymbols requests.

yioneko commented 1 month ago

What's your > echo $LANG? In coc.nvim the locale could be read from env variable: https://github.com/neoclide/coc.nvim/blob/33d0a5233cf68e6f54a78e3c3c20958c96f3e4cc/src/language-client/utils/index.ts#L7-L11 That may be not in one of the valid locale values for tsserver: https://github.com/yioneko/vtsls/blob/d180d88c7a85b7d6aa53b11c278ecb736e186167/packages/service/configuration.schema.json#L601-L612

You can try to manually set the config option typescript.locale to any listed value above.

PHSix commented 1 month ago

What's your > echo $LANG? In coc.nvim the locale could be read from env variable: https://github.com/neoclide/coc.nvim/blob/33d0a5233cf68e6f54a78e3c3c20958c96f3e4cc/src/language-client/utils/index.ts#L7-L11 That may be not in one of the valid locale values for tsserver:

https://github.com/yioneko/vtsls/blob/d180d88c7a85b7d6aa53b11c278ecb736e186167/packages/service/configuration.schema.json#L601-L612

You can try to manually set the config option typescript.locale to any listed value above.

right. Thanks for the answer. My LANG is zh_CN.UTF-8.This should be the problem with reporting errors.