最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

language server protocol - Completion items not appearing with LSP in neovim - Stack Overflow

programmeradmin3浏览0评论

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.

发布评论

评论列表(0)

  1. 暂无评论