Fixed the language server crashing upon a go to definition request on… #209
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes the textDocument/definition crash on untracked files, in other words files that haven't been opened yet.
This problem is described here:
neovim LSP <-> arduino-language-server crashes on textDocument/definition method. #159
A thing to note is that this only happens with files relative to the sketch root. Meaning if they are for example in a library folder somewhere and they get found by clangd the file just gets opened with the clangd path and this crash doesn't occur, because the check for whether they are tracked just never happens.
The lsp starts tracking the new file and opens it successfully. A thing to note is that this is currently true only for certain files (those with extensions .h and .hpp, set in the extToFileType map). For all other files with different extensions, the lsp returns an unknown file extension error and closes.
To be honest, I am not entirely certain about this behavior so I am also looking for a second opinion. On one hand the only real files that would be included are probably .h and .hpp. On the other hand closing the entire lsp just because of this doesn't really make sense to me. It could also make sense to have a list of allowed extensions that's passed to the lsp via an argument.
Also, I kind of want to write a test for this, but I am not even sure where to put it
(accidentally closed previous pr)