admin管理员组

文章数量:1352857

I'm writing a language server in typescript. The idea of the language server is to provide snippets, go-to-def, and hover in CSS files for design tokens (aka css variables)

Here's the handler for textDocument/completion:

export function completion({ params }: CompletionRequestMessage): null | CompletionList {
  tokens ??= getAllTokens();
  const word = getCSSWordAtPosition(params.textDocument.uri, params.position);
  if (!word) return null;
  const items: CompletionItem[] = tokens
    .filter(x => x.name?.replaceAll('-','').startsWith(word.replaceAll('-','')))
    .map(token => ({
      label: token.name!.replaceAll('-', '')!,
      kind: CompletionItemKind.Snippet,
      insertText: `var(--${token.name})$0`,
      documentation: token.$description && {
        value: getTokenMarkdown(token),
        kind: MarkupKind.Markdown,
      },
    }) satisfies CompletionItem);
  return {
    items,
    isIncomplete: false,
    itemDefaults: {
      insertTextFormat: InsertTextFormat.Snippet,
    }
  }
}

Which produces this ResponseMessage for a document change in which the current word is rhcolorblue10:

Content-Length: 457

{"id":7,"result":{"items":[{"label":"rhcolorblue10","kind":15,"insertText":"var(--rh-color-blue-10)$0","documentation":{"value":"`--rh-color-blue-10` *<`color`>*:\n\n  **#e0f0ff**\n\nAlert - Info background","kind":"markdown"}},{"label":"rhcolorblue10hsl","kind":15,"insertText":"var(--rh-color-blue-10-hsl)$0"},{"label":"rhcolorblue10rgb","kind":15,"insertText":"var(--rh-color-blue-10-rgb)$0"}],"isIncomplete":false,"itemDefaults":{"insertTextFormat":2}}}

As far as I can tell, that should be all kosher. Nonetheless, completion items are not appearing in neovim, via blink.cmp, when then do appear for other LSP servers.

here is the LSP configuration I'm using, which works for my textDocument/hover implementation:

---@type vim.lsp.ClientConfig
return {
  cmd = { 'design-tokens-languageserver' },
  root_markers = { '.git' },
  filetypes = {
    'css',
  },
  settings = { },
}

Am I missing something? Why are completion items not appearing in the completion menu?

Update 02-04-2025: I get the same behaviour when returning all of the snippets every time with isIncomplete: false, and the same when returning an CompletionItem[] with all snippets every time. I have also reproduced the same behaviour in vscodium and zed.

本文标签: language server protocolCompletion items not appearing with LSP in neovimStack Overflow