-
Notifications
You must be signed in to change notification settings - Fork 37
Description
I was getting the following error over and over on Windows using lsp-mode
in Emacs. This was both with the 0.0.9 release and with a build from master (merging in #48 to resolve the xerrors issue). (My computer had to reboot for unrelated reasons between receiving the error and posting this so cannot post the exact errors).
go panic runtime error invalid memory address or nil pointer dereference
The stack pointed to langserver/did_open.go:12
specifically the fileURL definition. Comparing this to the lsp-mode logs it was trying to open a file located at /C:/Users/acmeuser/git/tf-test/main.tf
since the original fileURL being passed was file:///C:/Users/acmeuser/git/tf-test/main.tf
. This does not work for Windows since it defines the protocol as file:///
not file://
. Updating with the below diff and recompiling resolved the issue.
I'm willing to open a PR for this change, however I'm aware it would also require updating to account for Windows vs Linux and I'm not familiar enough with Go to do so (without research first)
diff --git a/langserver/did_open.go b/langserver/did_open.go
index bc36ec5..6bd3a17 100644
--- a/langserver/did_open.go
+++ b/langserver/did_open.go
@@ -8,7 +8,7 @@ import (
)
func TextDocumentDidOpen(ctx context.Context, vs lsp.DidOpenTextDocumentParams) error {
- fileURL := strings.Replace(string(vs.TextDocument.URI), "file://", "", 1)
+ fileURL := strings.Replace(string(vs.TextDocument.URI), "file:///", "", 1)
DiagsFiles[fileURL] = tfstructs.GetDiagnostics(fileURL, fileURL)
TextDocumentPublishDiagnostics(Server, ctx, lsp.PublishDiagnosticsParams{