Skip to content
/ LSP Public

🚧 A language server protocol built with Go and every step documented for educational purposes.

Notifications You must be signed in to change notification settings

kaandesu/LSP

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

LSP

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:

Checkpoint 1

  • 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-op handleMessage function

Checkpoint 2: <-- You are here

  • Recieve basic messages from the lsp client and log them
  • Decoding the initialize
  • Initialize response
  • Text Document Synchronization

Checkpoint 2

1- Basic logging when msg recieved from lsp client

// main.go
func handleMessage(logger *log.Logger, msg any) {
	logger.Println(msg)
}

Starting the LSP from Neovim

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

About

🚧 A language server protocol built with Go and every step documented for educational purposes.

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published