Skip to content
New issue

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

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

Already on GitHub? # to your account

terraform-lsp crashes at initialization on Windows (Emacs) #50

Closed
jleechp-occm opened this issue Jan 3, 2020 · 1 comment · Fixed by #61
Closed

terraform-lsp crashes at initialization on Windows (Emacs) #50

jleechp-occm opened this issue Jan 3, 2020 · 1 comment · Fixed by #61

Comments

@jleechp-occm
Copy link

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{
AubreySLavigne added a commit to AubreySLavigne/terraform-lsp that referenced this issue Feb 22, 2020
This is in response to issue at: juliosueiras#50

A panic would be raised on Windows computers, where removing the
file:// scheme would still have an invalid leading slash
(e.g. '/C:/Users/...').
AubreySLavigne added a commit to AubreySLavigne/terraform-lsp that referenced this issue Feb 22, 2020
This is in response to issue at: juliosueiras#50

A panic would be raised on Windows computers, where removing the
file:// scheme would still have an invalid leading slash
(e.g. '/C:/Users/...').

Fixes juliosueiras#50
@AubreySLavigne
Copy link
Contributor

Linked PR uses the URI methods from the original go-language-server project. If we want, we can vendor or import, etc. I also resolved the same issue with the did_change and complete functions.

I don't have a Windows computer to verify these changes, but this should resolve the issue as stated.

Always open to feedback.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants