Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

neovim LSP <-> arduino-language-server crashes on textDocument/definition method. #159

Open
3 tasks done
amrlsayed opened this issue May 26, 2023 · 0 comments
Open
3 tasks done
Labels
type: imperfection Perceived defect in any part of project

Comments

@amrlsayed
Copy link

Describe the problem

"nvim" LSP client detach from arduino-language-server with error Unresolved .ino path on textDocument/definition method, when the definition is located on a "not tracked" file.
I learned from the source code that the "tracked files" are those which are saved from textDocument/didOpen methods. and to send that from "nvim", I just open the file containing the definition once.

To reproduce

  1. Create a sketch using arduino-cli
arduino-cli sketch new test_server
  1. Create another file(callme.ino) along with the main sketch file(test_server.ino)
  2. Add the following to callme.ino
void callme(void)
{
  Serial.println("Hello World!");
}
  1. Add the following to test_server.ino
void setup() {
  callme();
}
void loop() {
}
  1. Using neovim/nvim-lspconfig configure LSP client by adding the following to your init.lua
require'lspconfig'.arduino_language_server.setup{
  filetypes = {"arduino", "cpp"},
  cmd = {"arduino-language-server",
         "-cli-config",
  "<PATH-TO-CONFIG/arduino-cli.yaml>",
         "-log",
         "-logpath",
 "<PATH-TO-LOG-FOLDER>"}
}
  1. Open nvim
nvim test_server.ino
  1. Move the cursor to callme function call and run
:lua vim.lsp.buf.definition()

Expected behavior

From the text editor point of view, the callme.ino file should get opened and the cursor should be on the function callme.

Arduino Language Server version

0.7.4 and latest main branch commit 6c64232f29f8e61

Arduino CLI version

0.27.1

Operating system

Linux

Operating system version

Ubuntu 22

Additional context

Logged Error.

    !!! Unresolved .ino path: <PATH-TO-/callme.ino>
    !!! Known doc paths are:
    !!! <PATH-To-/test_server/test_server.ino>

I fixed the problem suppressing the error by changing the idePathToIdeURI() function to

func (ls *INOLanguageServer) idePathToIdeURI(logger jsonrpc.FunctionLogger, inoPath string) (lsp.DocumentURI, error) {
	if inoPath == sourcemapper.NotIno.File {
		return sourcemapper.NotInoURI, nil
	}
	doc, ok := ls.trackedIdeDocs[inoPath]
	if !ok {
		logger.Logf("    !!! Unresolved .ino path: %s", inoPath)
		logger.Logf("    !!! Known doc paths are:")
		for p := range ls.trackedIdeDocs {
			logger.Logf("    !!! > %s", p)
		}
		uri := lsp.NewDocumentURI(inoPath)
		return uri, nil //&UnknownURIError{uri} <-- EDIT HERE -->
	}
	return doc.URI, nil
}

But I do not think this is a good solution and would introduce other problems.

Other tries I made

I tried to open the project with several commands but all gave the same behavior.

nvim test_server.ino
nvim .
nvim test_server.ino callme.ino

The only workaround that leads to opening the definition is by opening the callme.ino file :e callme.ino explicitly once before trying to call textDocument/definition.

Issue checklist

  • I searched for previous reports in the issue tracker
  • I verified the problem still occurs when using the latest version
  • My report contains all necessary details
@amrlsayed amrlsayed added the type: imperfection Perceived defect in any part of project label May 26, 2023
@arduino arduino locked as off-topic and limited conversation to collaborators Jun 26, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
type: imperfection Perceived defect in any part of project
Projects
None yet
Development

No branches or pull requests

1 participant