展示 HN:Scheme-langserver – 使用静态分析消化不完整的代码
Show HN: Scheme-langserver – Digest incomplete code with static analysis

原始链接: https://github.com/ufo5260987423/scheme-langserver

## scheme-langserver:一种新的Scheme代码编辑方法 Z. Wang 在第18届欧洲Lisp研讨会 (ELS`25) 上介绍了 `scheme-langserver`,这是一种语言服务器协议 (LSP) 实现,旨在改善 Scheme 编程体验。与依赖 REPL 或简单分词的现有 Lisp 语言服务器 (Geiser, Racket LSP 等) 不同,`scheme-langserver` 利用静态代码分析来实现自动补全、“跳转到定义”和类型推断等功能——即使在不完整代码中也能实现。 该项目解决了分析 Scheme 灵活语法的挑战,特别是宏,以提供更准确的代码理解。主要功能包括对 R6RS/R7RS/S7 标准的支持、跨平台索引、自制类型推断系统(集成到自动补全中)以及与 Akku 包管理器的兼容性。 `scheme-langserver` 目前正在积极开发中,可通过 VSCode 使用,是一个社区驱动的开源项目,寻求贡献和资金。虽然仍包含错误,但它代表着朝着更强大、更智能的 Scheme 开发环境迈出的重要一步。进一步的开发目标包括数据流分析以及自制类型推断系统的综合指南,记录在一本计划出版的书籍中。 **项目和资源地址:** [https://doi.org/10.5281/zenodo.15384882](https://doi.org/10.5281/zenodo.15384882) (由于潜在的访问限制,提供镜像)。

## Scheme-langserver:为 Lisp 带来现代 IDE 功能 一位 Hacker News 的开发者发布了“scheme-langserver”项目,旨在改善 Scheme 和 Lisp 的开发体验。由于缺乏其他现代语言中常见的强大 IDE 类功能——例如自动补全、类型推断和“跳转到定义”——开发者对此感到沮丧,因此构建了这个语言服务器协议 (LSP) 实现。 该项目目前提供这些功能,并正在达到“自我提升”阶段,即它能够辅助自身的开发。它利用 Chez Scheme 的词法分析器,但承认存在一些相关的初始错误,并计划在未来进行修复。 未来的开发重点是一个可定制的宏展开器,允许用户在不修改核心项目的情况下定制 LSP 行为。开发者欢迎反馈和讨论,认为对话是一种有价值的支持形式。该项目在 GitHub 上可用,并提供文档和演示视频。
相关文章

原文

Ask DeepWiki

You may read my paper and cite like this

WANG, Z. (2025, May 12). Scheme-langserver: Treat Scheme Code Editing as the First-Class Concern. The 18th European Lisp Symposium (ELS`25), Zurich. https://doi.org/10.5281/zenodo.15384882

Due to GitHub may block Chinese IP addresses, I have to copy this repository to here and here. I will continually update all repositories but I can't guarrentee. I now also collaborate with XmacsLabs, you may also find a fork here.

default.mp4

Now, VSCode can use scheme-langserver! Please refere HERE.

NOTE: There're many many bugs in scheme-langserver. I'm just fixing and appealing help from the community. Please be patient.

NOTE: you can find the auto generated type information here. It's now mainly used for next-stage-development (maybe include AKKU) and debugging.

Implementing support like autocomplete, goto definition, or documentation on hover is a significant effort for programming. However, comparing to other language like java, python, javascript and c, language server protocol implementation for lisp language are just made in a vacuum. Geiser, racket langserver and swish-lint etc., their works are all based on repl(Read-Eval-Print Loop) or keyword tokenizer instead of programming. For example, if a programmer was coding on an unaccomplished project, in which the codes were not fully executable, Geiser or any others would only complete top-level binding identifiers listed by environment-symbols procedure (for Chez), or complete symbols instead of identifiers. Which means for local bindings and unaccomplished codes, though making effort for programming is supposed of the importance mostly, Geiser and its counterparts help nothing on recognizing identifier's valid scope. Familiar cases occur with goto definition and many other functionalities.

A primary cause is, for scheme and other lisp dialects, their abundant data sets and flexible control structures raise program analysis a big challenge. Especially the macro, it seems like that scheme is mainly used for genius and meta/macro programming. But I say no. Scheme can make many interesting things if a better programming environment is provided. And now you may STARTUP HERE.

This package is a language server protocol implementation helping scheme programming. It provides completion, definition and type inference. These functionalities are established on static code analysis with r6rs standard and some obvious rules for unaccomplished codes. This package itself and related libraries are published or going to be published with Akku, which is a package manager for Scheme.

This package also has been tested with Chez Scheme versions 9.4 and 9.5. A detailed test on version 10.0.0 will be done after upgrading my laptop OS to a newer version.

I do this open source work just in my spare time and I can contribute many splendid ideas to the community like embedding data flow analysis into scheme-langserver or many other things. And I'm continuously asking for much more donation or funding. You can donate with this patreon page or 爱发电.

Compilation , Installation & Configuration is HERE

Debug or Issue Bugs, you may find THIS helpful.

I'll keep fixing bugs, profiling the code, and collecting information for my giant book on homemade type inference system. This will take me about 1 years. Further developments including a VScode plugin and data flow analysis. But actually, I'm now setting this open source work a part-time job, and I can not guarantee a schedule.

2.0.3 Fix wrongly pretty-print bugs, they mixtured with standard IO.

Previous releases please refer to this file.

  1. Top-level and local identifiers binding completion. Top-level and local identifiers binding
  2. Goto definition. Goto definition with telescope.nvim
  3. Compatible with package manager: Akku.
  4. File changes synchronizing and corresponding index changing.
  5. Hover.
  6. References and document highlight (document-scoped references). Find references with telescope.nvim
  7. Document symbol. Find document symbols with telescope.nvim
  8. Catching *-syntax(define-syntax, let-syntax, etc.) based local identifier binding.
  9. Cross-platform parallel indexing.
  10. Self-made source code annotator to be compatible with .sps files.
  11. Peephole optimization for API requests with suspendable task.
  12. Type inference with a homemade DSL interpreter(I'm very proud of it!). And now it has been embedded into the auto-completion. As the following figure indicated, the "length-b" and "length-a" having "integer?" type are in the front of those recommended options because they can match the parameter type requiring from "<=". Autocompletion with type inference A test in can prove this result, just run scheme --script tests/protocol/apis/test-completion.sps and the log file scheme-langserver.log would contain results like this:
  13. By switching top environments, scheme-langserver supports R6RS/R7RS/S7.
send-message
2023 11 21 11 26 41 967266866
{"jsonrpc":"2.0","id":"3","result":[{"label":"length-a"},{"label":"length-b"},{"label":"lambda"},{"label":"latin-1-codec"},{"label":"lcm"},{"label":"least-fixnum"},{"label":"length"},{"label":"let"},{"label":"let*"},{"label":"let*-values"},{"label":"let-syntax"},{"label":"let-values"},{"label":"letrec"},{"label":"letrec*"},{"label":"letrec-syntax"},{"label":"lexical-violation?"},{"label":"list"},{"label":"list->string"},{"label":"list->vector"},{"label":"list-ref"},{"label":"list-sort"},{"label":"list-tail"},{"label":"list?"},{"label":"log"},{"label":"lookahead-char"},{"label":"lookahead-u8"}]}
  1. Abstract interpreter for identifier catching among different file extensions like scm, ss, sps, sls and sld.
  2. Code diagnostic. Now only support to diagnoses library-not-found. Fail to find library
  1. Renaming.
  2. Fully compatible with r6rs standard.
  3. Step-by-step macro expander: well, I actually have implemented one and I wanted to make it a key step catching identifier binding in self-defined macros. Now, I find this catching is much harder than I thought, and the expander I don't know where it could work.
  4. Code eval.
  5. Add cross-language semantic supporting. Well, would java, c, python and many other languages can be supported with an AST transformer?
  6. Extract expression/statements into a procedure.

Almost all key procedures and APIs are tested. My work is just so rough but useful, maybe you would like to find what I've done in tests directory or just run following command in {scheme-langserver-root-directory}

NOTE It's hard to do test with threaded environment. So, current tests focus on single thread.

Use Scheme-langserver for Other Purpose

Script-Fu is based on an interpreted language called Scheme, and works by using functions that interact with GIMP's internal functions. Taking this page's script as an example, you can apply scheme-langserver with script file with "SCM" extension.

Well, I'm also interested in OMN (Opusmodus Notation) and AutoLisp. But I still have many things to do.

find . -name "*.sls" ! -path "./.akku/*" |xargs wc -l
  1. Scheme-langserver: Treat Scheme Code Editing as the First-Class Concern.
  2. Catching identifier bindings
  3. Synchronizing
  4. Type inference,类型推断(Deprecated, and I'm writing a Chinese book for it)
  5. API Analysis
  6. Deepwiki
  7. Scheme-langserver develop guide.

Star History Chart

Contributors

联系我们 contact @ memedata.com