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

刚才在开车,没有合并了,感谢 @wsw 大佬。

这个项目坑很多,但是认识了很多编程大佬呀,写代码又快质量又高。

大佬加了一个 lsp-bridge-return-from-def 命令,配合 lsp-bridge-find-def 命令,研究代码的时候超级有用。

我认为主要还是 Emacs 用户响应做得不好。

在我这台老爷笔记本上,VSCode 除了占资源很凶以外,不觉得它性能多好。LSP 也是半天没结果,但是不妨碍做其他操作,感觉起来就是比较流畅。Emacs 就必需等到上一个任务结束了,才能响应下一个动作。

对,这就是有多线程和没多线程的区别。

脚本语言可以慢,但是有多线程可以保证最起码用户响应的这线程代码不会阻塞。

有个补丁我要撤销了,有编解码问题。

已经修复了,大家可以放心使用。

lsp-bridge.el的minor mode里面,

(define-minor-mode lsp-bridge-mode
  "LSP Bridge mode."
  :keymap lsp-bridge-mode-map # 能加上这行吗?
  :init-value nil
  (if lsp-bridge-mode
      (lsp-bridge--enable)
    (lsp-bridge--disable)))

可以呀,大佬发个补丁吧。

想让大佬自己改改的,我的水平太差。已提pr。

对于文件中有tab等字符的,find-def 时lsp-bridge使用的列号(current-column)不是lsp所需要的列号。 如tab-width为4时,fmtf的lsp列应该是1(看所使用的 PositionEncodingKind),而不是4。

func main() {
    fmt.Println("hello")
}

建议编辑器全部用空格替代,不要使用Tab。

话说 golang 官方标准就是 tab 缩进(go 很多方面都挺奇葩的其实

--- Recv message
{
   "seq": 0,
   "type": "response",
   "command": "unknown",
   "request_seq": 0,
   "success": false,
   "message": "Error processing request. Unexpected token C in JSON at position 233\nSyntaxError: Unexpected token C in JSON at position 233\n    at JSON.parse (<anonymous>)\n    at IOSession.Session.parseMessage (/home/parallels/.nvm/versions/node/v16.14.0/lib/node_modules/typescript/lib/tsserver.js:174110:29)\n    at IOSession.Session.onMessage (/home/parallels/.nvm/versions/node/v16.14.0/lib/node_modules/typescript/lib/tsserver.js:174065:36)\n    at Interface.<anonymous> (/home/parallels/.nvm/versions/node/v16.14.0/lib/node_modules/typescript/lib/tsserver.js:176675:31)\n    at Interface.emit (node:events:520:28)\n    at Interface._onLine (node:readline:487:10)\n    at Interface._normalWrite (node:readline:661:12)\n    at Socket.ondata (node:readline:269:10)\n    at Socket.emit (node:events:532:35)\n    at addChunk (node:internal/streams/readable:315:12)\n    at readableAddChunk (node:internal/streams/readable:289:9)\n    at Socket.Readable.push (node:internal/streams/readable:228:10)\n    at Pipe.onStreamRead (node:internal/stream_base_commons:190:23)"
}

--- Recv message
{
   "seq": 0,
   "type": "response",
   "command": "unknown",
   "request_seq": 0,
   "success": false,
   "message": "Error processing request. Unexpected end of JSON input\nSyntaxError: Unexpected end of JSON input\n    at JSON.parse (<anonymous>)\n    at IOSession.Session.parseMessage (/home/parallels/.nvm/versions/node/v16.14.0/lib/node_modules/typescript/lib/tsserver.js:174110:29)\n    at IOSession.Session.onMessage (/home/parallels/.nvm/versions/node/v16.14.0/lib/node_modules/typescript/lib/tsserver.js:174065:36)\n    at Interface.<anonymous> (/home/parallels/.nvm/versions/node/v16.14.0/lib/node_modules/typescript/lib/tsserver.js:176675:31)\n    at Interface.emit (node:events:520:28)\n    at Interface._onLine (node:readline:487:10)\n    at Interface._normalWrite (node:readline:661:12)\n    at Socket.ondata (node:readline:269:10)\n    at Socket.emit (node:events:532:35)\n    at addChunk (node:internal/streams/readable:315:12)\n    at readableAddChunk (node:internal/streams/readable:289:9)\n    at Socket.Readable.push (node:internal/streams/readable:228:10)\n    at Pipe.onStreamRead (node:internal/stream_base_commons:190:23)"
}

--- Recv message
{
   "seq": 0,
   "type": "response",
   "command": "unknown",
   "request_seq": 0,
   "success": false,
   "message": "Error processing request. Unexpected token C in JSON at position 291\nSyntaxError: Unexpected token C in JSON at position 291\n    at JSON.parse (<anonymous>)\n    at IOSession.Session.parseMessage (/home/parallels/.nvm/versions/node/v16.14.0/lib/node_modules/typescript/lib/tsserver.js:174110:29)\n    at IOSession.Session.onMessage (/home/parallels/.nvm/versions/node/v16.14.0/lib/node_modules/typescript/lib/tsserver.js:174065:36)\n    at Interface.<anonymous> (/home/parallels/.nvm/versions/node/v16.14.0/lib/node_modules/typescript/lib/tsserver.js:176675:31)\n    at Interface.emit (node:events:520:28)\n    at Interface._onLine (node:readline:487:10)\n    at Interface._normalWrite (node:readline:661:12)\n    at Socket.ondata (node:readline:269:10)\n    at Socket.emit (node:events:532:35)\n    at addChunk (node:internal/streams/readable:315:12)\n    at readableAddChunk (node:internal/streams/readable:289:9)\n    at Socket.Readable.push (node:internal/streams/readable:228:10)\n    at Pipe.onStreamRead (node:internal/stream_base_commons:190:23)"
}

--- Recv message
{
   "seq": 0,
   "type": "response",
   "command": "unknown",
   "request_seq": 0,
   "success": false,
   "message": "Error processing request. Unexpected end of JSON input\nSyntaxError: Unexpected end of JSON input\n    at JSON.parse (<anonymous>)\n    at IOSession.Session.parseMessage (/home/parallels/.nvm/versions/node/v16.14.0/lib/node_modules/typescript/lib/tsserver.js:174110:29)\n    at IOSession.Session.onMessage (/home/parallels/.nvm/versions/node/v16.14.0/lib/node_modules/typescript/lib/tsserver.js:174065:36)\n    at Interface.<anonymous> (/home/parallels/.nvm/versions/node/v16.14.0/lib/node_modules/typescript/lib/tsserver.js:176675:31)\n    at Interface.emit (node:events:520:28)\n    at Interface._onLine (node:readline:487:10)\n    at Interface._normalWrite (node:readline:661:12)\n    at Socket.ondata (node:readline:269:10)\n    at Socket.emit (node:events:532:35)\n    at addChunk (node:internal/streams/readable:315:12)\n    at readableAddChunk (node:internal/streams/readable:289:9)\n    at Socket.Readable.push (node:internal/streams/readable:228:10)\n    at Pipe.onStreamRead (node:internal/stream_base_commons:190:23)"
}

每次给 volar 发送完 textDocument/completion 请求之后,都会返回这个错误,然后下次请求的时候才会返回上个请求的响应结果,导致总错着一个。。。

有人遇到过么,非 Node 实现的估计也没有这问题, 而 ts-ls 是好好的,都不好debug了

lsp-bridge-restart-process 继续调试,排除一下子进程管道缓冲被填满的情况。

这个试过了不行

我这边也遇到rename的时候,第一次可以,第二次要刷两遍的问题,我想想是不是我哪里设计有问题。

这个估计是我解析 lsp server 消息协议逻辑的锅。

这个错误是node返回来的,不知道它拿到的json是啥 导致解析出错了

除了补全之外,有些操作是不是用同步体验会好点,比如 lsp-bridge-find-def ,我试了下 lsp-bridge-call-sync,感觉比异步好些,我这边用异步查找定义时经常就是没反应,跳不过去,我觉得我宁可等一会,因为找定义时我是不会想着去干其它事的,就是想着跳过去。当然代码里都留了口子了,大概就是说下使用体会

等我把底层消息解析的逻辑bug处理了,现在是漏消息了,说不定就漏了宁你迷惑的消息呢,稍等。

1 个赞

没事,我们慢慢改进。