Scheme-langserver
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 are not fully runnable, Geiser or any others would only complete top-level binding identifiers listed by environment-symbols
procedure (for Chez). 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. 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. In fact, scheme even don't have commonly acknowledged project management frameworks and corresponding extension system. As for extensions SS, and SCM, most programmers suppose their codes are writing for a running environment and don't provide any library information. Although with Akku and Snow, SLS and SLD files can base a project on a stable library framework, involve
, load
and many other procedures which maintain dynamic library linkages make static code analysis telling less.
This package is a language server protocol implementation helping scheme programming. It provides completion, definition and will provide many other functionalities. 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.
Your donation will make this world better. Also, you can issue your advice and I might implement if it was available.
Setup
Building
Pre-require
NOTE If you wanted to enable scheme-langserver's muti-thread feature, it would require Chez Scheme to have been compiled with the --threads option. This uses chez scheme's FFI to call up the pipe() and poll() system calls, and therefore requires a UNIX-like operating system to function correctly. It has been tested with linux and should work on the BSDs and on Mac OS X. If using OS X, the glibtool package will be required.
NOTE chez-exe requires boot files and kernel files of Chez Scheme. So, the compile command maybe like follows:
scheme --script gen-config.ss --bootpath /path-to-ChezScheme/{machine-type}/boot/{machine-type}
For Linux
git clone https://github.com/ufo5260987423/scheme-langserver
cd scheme-langserver
akku install
bash .akku/env
compile-chez-program run.ss
./run path-to-logfile
TODO: for Windows
LunarVim
Installation forIn the near future, I will pull request to mason.nvim and mason-lspconfig.nvim. In that case, you will be able to get this implementation automatically with LunarVim.
But now, for installed plugin nvim-lspconfig, we have to manually do some installation: after manually building from above step Building, an executable file run
would be available at {path-to-run}
. Then, create file ~/.local/share/lunarvim/site/pack/packer/start/nvim-lspconfig/lua/lspconfig/server_configurations/scheme_langserver.lua
as follows:
local util = require 'lspconfig.util'
local bin_name = '{path-to-run}'
local cmd = { bin_name }
return {
default_config = {
cmd = cmd,
filetypes = { 'scheme' },
root_dir = util.find_git_ancestor,
single_file_support = true,
},
docs = {
description = [[
https://github.com/ufo5260987423/scheme-langserver
`scheme-langserver`, a language server protocol implementation for scheme
]] ,
},
}
Then configure your ~/.config/lvim/init.lua
and add following codes like:
require 'lspconfig'.scheme_langserver.setup {}
NOTE For LunarVim, default scheme file extension doesn't include ".SLS". A patch to
.local/share/lunarvim/lvim/ftdetec/
is to addsls.lua
file as following:
vim.cmd [[ au BufRead,BufNewFile *.sls set filetype=scheme ]]
VScode
TODO: Installation forStatus
This project is still in early development, so you may run into rough edges with any of the features. The following list shows the status of various features.
Features
NOTE I made some configuration with
.config/lvim/config.lua
like following
vim.keymap.set('n', 'gr', builtin.lsp_references, {})
vim.keymap.set('n', 'gd', builtin.lsp_definitions, {})
- Top-level and local identifiers binding completion.
- Goto definition.
- Compatible with package manager: Akku.
- File changes synchronizing and corresponding index changing.
- Hover.
- References.
- Document symbol.
TODOs
- Renaming.
- *-syntax(define-syntax, let-syntax, etc.) based local identifier binding.
- Fully compatible with r6rs standard.
- Cross-platform Parallel indexing.
- Macro expanding.
- Code eval.
- Code diagnostic.
- Add cross-language semantic supporting.
- Self-made annotator.
- Type inference.
TODO:Contributing
Debug
Output Log
Following tips from Building, Installation for Lunar Vim and Installation for VScode, if anyone wants to do some developing and log something, it will be convenient to add path-to-log-file
and re-write file ~/.local/share/lunarvim/site/pack/packer/start/nvim-lspconfig/lua/lspconfig/server_configurations/scheme_langserver.lua
as follows:
local util = require 'lspconfig.util'
local bin_name = '{path-to-run}'
local cmd = { bin_name ,"path-to-log-file"}
return {
default_config = {
cmd = cmd,
filetypes = { 'scheme' },
root_dir = util.find_git_ancestor,
single_file_support = true,
},
docs = {
description = [[
https://github.com/ufo5260987423/scheme-langserver
`scheme-langserver`, a language server protocol implementation for scheme
]] ,
},
}
Recurring with Log
With above output log, you may use tests/log-debug.sps
recurring bugs:
- Rename
{path-to-log}
(usually~/scheme-langserver.log
) as~/ready-for-analyse.log
; - run
scheme --script tests/log-debug.sps
Test
Almost all key procedures and APIs are tested. You can find out what I've done in tests
directory or just run following command in {scheme-langserver-root-directory}
bash test.sh