A language server protocol built with GO for educational purposes.
( Check LSP specification for more information.)Every progress will be tagged as checkpoints. Every tag will have a different README, more detailed explanation for each checkpoint. To be updated contents of the checkpoints:
- Basic
DecodeMessage
function - Basic
EncodeMessage
function - Basic
Split
function for the logger - Basic tests for the functions above
- Basic
Logger
function - Starting
Stdin scanner
in main, with no-ophandleMessage
function
Checkpoint 2: <-- You are here
- Recieve basic messages from the lsp client and log them
- Decoding the
initialize
- Initialize response
- Text Document Synchronization
1- Basic logging when msg recieved from lsp client
// main.go
func handleMessage(logger *log.Logger, msg any) {
logger.Println(msg)
}
in some nvim lua file:
Example below, attaches the lsp client when buffer has the type 'markdown'.
go build main.go
should be called, and used it's path for the cmd
--- add this to somewhere with autocmds
local client = vim.lsp.start_client({
name = "kaandesu/LSP",
cmd = { "path/to/the/build/LSP/main" },
filetypes = { "markdown" },
})
if not client then
vim.notify("there is something wrong with the client")
end
vim.api.nvim_create_autocmd("FileType", {
pattern = { "md", "markdown" },
callback = function()
if not client then
vim.notify("there is something wrong with the client")
return
end
vim.notify("custom lsp attached!")
vim.lsp.buf_attach_client(0, client)
end,
})
About Server Lifecycle - specs
1- Initialize Request:
-
The initialize request is sent as the first request from the client to the server.
-
Server is not allowed to send any requests or notifications to the client until it has responded with an InitializeResult
-
initialize
request may only be sent once -
Afterwards, LSP shall respond with a
InitializeResult
NEXT:
- TBD
Honorable Mentions
- tjdevries/educationalsp
- Brazil