lsp-bridge -- 速度最快的语法补全插件

sumneko_lua lsp server会把workspace/configuration发给client,但是client没处理,请问该怎么改代码?

Eval in Emacs: (lsp-bridge--first-start '54143)
Cache action change_cursor, wait for file /Users/albert/workspace/lua/test.lua to open it before executing.

--- Send request initialize: 23015
{
   "jsonrpc": "2.0",
   "method": "initialize",
   "params": {
      "processId": 61205,
      "rootPath": "/Users/albert/workspace/lua/test.lua",
      "clientInfo": {
         "name": "emacs",
         "version": "GNU Emacs 28.1 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.24.33, cairo version 1.17.6)\n of 2022-04-04"
      },
      "rootUri": "file:///Users/albert/workspace/lua/test.lua",
      "capabilities": {
         "callHierarchy": {
            "dynamicRegistration": false
         },
         "textDocument": {
            "completion": {
               "completionItem": {
                  "commitCharactersSupport": true,
                  "deprecatedSupport": true,
                  "documentationFormat": [
                     "markdown",
                     "plaintext"
                  ]
               }
            }
         },
         "workspace": {
            "applyEdit": true,
            "configuration": true,
            "symbol": {
               "dynamicRegistration": false,
               "hierarchicalWorkspaceSymbolSupport": true,
               "symbolKind": {
                  "valueSet": [
                     1,
                     2,
                     3,
                     4,
                     5,
                     6,
                     7,
                     8,
                     9,
                     10,
                     11,
                     12,
                     13,
                     14,
                     15,
                     16,
                     17,
                     18,
                     19,
                     20,
                     21,
                     22,
                     23,
                     24,
                     25,
                     26
                  ]
               }
            },
            "workspaceEdit": {
               "resourceOperations": [
                  "rename",
                  "create",
                  "delete"
               ]
            },
            "workspaceFolders": true,
            "didChangeConfiguration": {
               "dynamicRegistration": true
            }
         }
      },
      "initializationOptions": {}
   },
   "id": 23015
}

--- Recv message:  window/logMessage

--- Recv message
{
   "jsonrpc": "2.0",
   "method": "window/logMessage",
   "params": {
      "message": "Log path: file:///Users/albert/.local/share/nvim/lsp_servers/sumneko_lua/extension/server/log/file_Users_albert_workspace_lua_test.lua.log",
      "type": 4
   }
}

--- Recv message:  23015
{
   "id": 23015,
   "jsonrpc": "2.0",
   "result": {
      "capabilities": {
         "codeActionProvider": {
            "codeActionKinds": [
               "",
               "quickfix",
               "refactor.rewrite",
               "refactor.extract"
            ],
            "resolveProvider": false
         },
         "completionProvider": {
            "resolveProvider": true,
            "triggerCharacters": [
               "\t",
               "\n",
               ".",
               ":",
               "(",
               "'",
               "\"",
               "[",
               ",",
               "#",
               "*",
               "@",
               "|",
               "=",
               "-",
               "{",
               "/",
               "\\",
               " ",
               "+",
               "?"
            ]
         },
         "definitionProvider": true,
         "documentHighlightProvider": true,
         "documentOnTypeFormattingProvider": {
            "firstTriggerCharacter": "\n"
         },
         "documentSymbolProvider": true,
         "executeCommandProvider": {
            "commands": [
               "lua.removeSpace",
               "lua.solve",
               "lua.jsonToLua",
               "lua.setConfig",
               "lua.autoRequire"
            ]
         },
         "foldingRangeProvider": true,
         "hoverProvider": true,
         "offsetEncoding": "utf-16",
         "referencesProvider": true,
         "renameProvider": {
            "prepareProvider": true
         },
         "semanticTokensProvider": {
            "full": false,
            "legend": {
               "tokenModifiers": [
                  "declaration",
                  "definition",
                  "readonly",
                  "static",
                  "deprecated",
                  "abstract",
                  "async",
                  "modification",
                  "documentation",
                  "defaultLibrary"
               ],
               "tokenTypes": [
                  "namespace",
                  "type",
                  "class",
                  "enum",
                  "interface",
                  "struct",
                  "typeParameter",
                  "parameter",
                  "variable",
                  "property",
                  "enumMember",
                  "event",
                  "function",
                  "method",
                  "macro",
                  "keyword",
                  "modifier",
                  "comment",
                  "string",
                  "number",
                  "regexp",
                  "operator"
               ]
            },
            "range": true
         },
         "signatureHelpProvider": {
            "triggerCharacters": [
               "(",
               ","
            ]
         },
         "textDocumentSync": {
            "change": 2,
            "openClose": true
         },
         "typeDefinitionProvider": true,
         "workspaceSymbolProvider": true
      },
      "serverInfo": {
         "name": "sumneko.lua"
      }
   }
}

--- Send notification: initialized
{
   "jsonrpc": "2.0",
   "method": "initialized",
   "params": {}
}

--- Recv message:  $/status/report

--- Recv message
{
   "jsonrpc": "2.0",
   "method": "$/status/report",
   "params": {
      "text": "\ud83d\ude3aLua",
      "tooltip": "Workspace   : /Users/albert/workspace/lua/test.lua\nCached files: 0/0\nMemory usage: 2M"
   }
}

--- Send notification: workspace/didChangeConfiguration
{
   "jsonrpc": "2.0",
   "method": "workspace/didChangeConfiguration",
   "params": {
      "settings": {
         "Lua": {
            "telemetry": {
               "enable": false
            },
            "workspace": {
               "library": {
                  "/Applications/VimR.app/Contents/Resources/NvimView_NvimView.bundle/Contents/Resources/runtime/lua": true
               },
               "maxPreload": 100000,
               "preloadFileSize": 10000
            }
         },
         "runtime": {
            "version": "Lua 5.1"
         },
         "diagnostics": {
            "enable": false
         }
      }
   }
}
Execute action change_cursor for file /Users/albert/workspace/lua/test.lua

--- Send notification: textDocument/didOpen
{
   "jsonrpc": "2.0",
   "method": "textDocument/didOpen",
   "params": {
      "textDocument": {
         "uri": "file:///Users/albert/workspace/lua/test.lua",
         "languageId": "lua",
         "version": 0,
         "text": "local albert = \"Albert\"\n\nprint(\"Hello World.\")\n"
      }
   }
}

--- Recv message:  $/status/report

--- Recv message
{
   "jsonrpc": "2.0",
   "method": "$/status/report",
   "params": {
      "text": "\ud83d\ude3aLua",
      "tooltip": "Workspace   : /Users/albert/workspace/lua/test.lua\nCached files: 0/0\nMemory usage: 1M"
   }
}

--- Recv message:  workspace/configuration

--- Recv message:  1       #### 这个message ####
{
   "id": 1,
   "jsonrpc": "2.0",
   "method": "workspace/configuration",
   "params": {
      "items": [
         {
            "scopeUri": "file:///Users/albert/workspace/lua/test.lua",
            "section": "Lua"
         },
         {
            "scopeUri": "file:///Users/albert/workspace/lua/test.lua",
            "section": "files.associations"
         },
         {
            "scopeUri": "file:///Users/albert/workspace/lua/test.lua",
            "section": "files.exclude"
         },
         {
            "scopeUri": "file:///Users/albert/workspace/lua/test.lua",
            "section": "editor.semanticHighlighting.enabled"
         },
         {
            "scopeUri": "file:///Users/albert/workspace/lua/test.lua",
            "section": "editor.acceptSuggestionOnEnter"
         }
      ]
   }
}

--- Recv message:  workspace/configuration

--- Recv message:  2
{
   "id": 2,
   "jsonrpc": "2.0",
   "method": "workspace/configuration",
   "params": {
      "items": [
         {
            "scopeUri": "file:///Users/albert/workspace/lua/test.lua",
            "section": "Lua"
         },
         {
            "scopeUri": "file:///Users/albert/workspace/lua/test.lua",
            "section": "files.associations"
         },
         {
            "scopeUri": "file:///Users/albert/workspace/lua/test.lua",
            "section": "files.exclude"
         },
         {
            "scopeUri": "file:///Users/albert/workspace/lua/test.lua",
            "section": "editor.semanticHighlighting.enabled"
         },
         {
            "scopeUri": "file:///Users/albert/workspace/lua/test.lua",
            "section": "editor.acceptSuggestionOnEnter"
         }
      ]
   }
}

你说的是 workspace/didChangeConfiguration 这个消息吗?

不是的。workspace/didChangeConfiguration 消息是client发给server的,而workspace/configuration是server发给client的,可以参考

client不响应workspace/configuration消息导致sumneko_lua无法完成workspace初始化。

--- Recv message:  workspace/configuration

--- Recv message:  1       #### 这个message ####

所有服务器发过来的消息都可以在 lsp-bridge/lspserver.py at ff28abcf675ce2e6e265a67a36ad48f45ec98a6c · manateelazycat/lsp-bridge · GitHub 这里截获,解析后再调用相应的方法返还给 lsp server

大佬这是怎么回事,好像开了两个补全窗口

难道我要把company关掉?

对,把 company 完全禁用,现在 lsp-bridge 只支持 corfu

补全的时候,他是直接把选项打印出来,我又要一个一个改,感觉有点不对

报一个issue吧

这个是因为 lsp-bridge 插入了 label,但是实际插入的应该是 textEdit 或 insertText 的内容。

is there any solution?
input method not working
@manateelazycat may I ask when python lsp should work, there is no completion in this case

another question is, when I switch to other file, such as from python to c++, completion does not work,


卧槽,没有人反映过这个问题吗

@manateelazycat

猫哥,用回车完成补全时,补全窗口还会继续打开,用 Tab 没问题。原因估计是因为Corfu 的回车默认绑定的是 Corfu-insert 命令。

提了个 issue:

不知道高手咋样。 对我来说,补全是真的爽啊,我用了10年matlab,基本上所有用的函数我都知道,但是还是喜欢补全的感觉,快啊。自动帮我把函数打出来。而且能够帮我自动输入括号,逗号啥的。 例如一个函数是: linspace(s1, s2, s3); 这里我只用tab在s1到s3跳转就能输入完成了,手动输入要逗号,空格,括号好麻烦。

遗憾的是,目前只有原生matlab和vscode的补全做的最好。emacs的matlab-mode还差点儿意思。准备有时间折腾一下。

1 个赞

有木有用 metals (0.11.1+158-06755eb9-SNAPSHOT) 的朋友,在 lsp-mode 下可以正常使用,但是在 lsp-bridge-mode 只有跳转能用 :sob:

我明天提个pr 改一下吧

1 个赞

增加了新命令 lsp-bridge-lookup-documentation 用于查看光标处符号的文档,需要安装 @tumashu 大佬的 posframe

目前为止,我个人需要的所有 LSP 功能全部都开发完毕,大佬们加油。

6 个赞

刚刚试用了一下, 在 Emacs 里调试 Kubernetes 的源码, 流畅度爆表, 准备直接替换 lsp mode 了

1 个赞

哈哈哈哈, 幸苦没有白费, 感谢认可。

折腾了一下,通过 cape 直接把 lsp-bridge 和 corfu-tabnine 混合在一起了,现在完美了。

怎么混合的代码大家可以参考 lazycat-emacs/init-lsp-bridge.el at master · manateelazycat/lazycat-emacs · GitHub

同学们,丢弃 company-mode 换 corfu 吧,真的很好用。

4 个赞

哈哈,sumneko_lua真是难搞啊,不过可以在lua lsp server上把所有的log打出来。和vimr的nvim-lsp对比了一下client和server交互的rpclog,照抄了nvim initialize时发送的capabilities,补齐貌似可以,跳转还报错。唉,睡觉了。

哈哈哈哈,LSP的好处是,实在不知道怎么搞, 就去打印 vim 和 vscode 的日志,把消息抄过来。

1 个赞