forked from golang/tools
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
internal/lsp: get file URI from beginFileRequest in SemanticTokens
Unguarded calls to span.URI.Filename() can panic. beginFileRequest handles this, so use the URI of the returned FileHandle instead. Fixes golang/vscode-go#1498 Change-Id: Ie48c27854e4a8ed8cca52ff6547ff580eccb5fd5 Reviewed-on: https://go-review.googlesource.com/c/tools/+/319529 Trust: Robert Findley <[email protected]> Run-TryBot: Robert Findley <[email protected]> Reviewed-by: Heschi Kreinick <[email protected]> gopls-CI: kokoro <[email protected]> TryBot-Result: Go Bot <[email protected]>
- Loading branch information
Showing
2 changed files
with
50 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// Copyright 2021 The Go Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style | ||
// license that can be found in the LICENSE file. | ||
|
||
package misc | ||
|
||
import ( | ||
"testing" | ||
|
||
"golang.org/x/tools/internal/lsp/protocol" | ||
. "golang.org/x/tools/internal/lsp/regtest" | ||
) | ||
|
||
func TestBadURICrash_VSCodeIssue1498(t *testing.T) { | ||
const src = ` | ||
-- go.mod -- | ||
module example.com | ||
go 1.12 | ||
-- main.go -- | ||
package main | ||
func main() {} | ||
` | ||
WithOptions( | ||
Modes(Singleton), | ||
EditorConfig{ | ||
AllExperiments: true, | ||
}, | ||
).Run(t, src, func(t *testing.T, env *Env) { | ||
params := &protocol.SemanticTokensParams{} | ||
const badURI = "http://foo" | ||
params.TextDocument.URI = badURI | ||
// This call panicked in the past: golang/vscode-go#1498. | ||
if _, err := env.Editor.Server.SemanticTokensFull(env.Ctx, params); err != nil { | ||
// Requests to an invalid URI scheme shouldn't result in an error, we | ||
// simply don't support this so return empty result. This could be | ||
// changed, but for now assert on the current behavior. | ||
t.Errorf("SemanticTokensFull(%q): %v", badURI, err) | ||
} | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters