From 45dd101d87843da2a383dd0ce49a8c8519ce766b Mon Sep 17 00:00:00 2001 From: Rebecca Stambler Date: Tue, 26 Mar 2019 21:11:20 -0400 Subject: [PATCH] internal/lsp: unescape uris before we convert them to span.URI This is the first step of fixing gopls on Windows. Change-Id: I20cea63051f448cba86996edaf7a8347b0d20bd1 Reviewed-on: https://go-review.googlesource.com/c/tools/+/169444 Reviewed-by: Ian Cottrell Run-TryBot: Ian Cottrell --- internal/lsp/server.go | 28 ++++++++++++++-------------- internal/span/uri.go | 3 +++ 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/internal/lsp/server.go b/internal/lsp/server.go index 5f6d2a7444..68fdfcf78a 100644 --- a/internal/lsp/server.go +++ b/internal/lsp/server.go @@ -92,7 +92,7 @@ func (s *server) Initialize(ctx context.Context, params *protocol.InitializePara var rootURI span.URI if params.RootURI != "" { - rootURI = span.URI(params.RootURI) + rootURI = span.NewURI(params.RootURI) } rootPath, err := rootURI.Filename() if err != nil { @@ -186,7 +186,7 @@ func (s *server) ExecuteCommand(context.Context, *protocol.ExecuteCommandParams) } func (s *server) DidOpen(ctx context.Context, params *protocol.DidOpenTextDocumentParams) error { - return s.cacheAndDiagnose(ctx, span.URI(params.TextDocument.URI), params.TextDocument.Text) + return s.cacheAndDiagnose(ctx, span.NewURI(params.TextDocument.URI), params.TextDocument.Text) } func (s *server) applyChanges(ctx context.Context, params *protocol.DidChangeTextDocumentParams) (string, error) { @@ -199,7 +199,7 @@ func (s *server) applyChanges(ctx context.Context, params *protocol.DidChangeTex return change.Text, nil } - file, m, err := newColumnMap(ctx, s.view, span.URI(params.TextDocument.URI)) + file, m, err := newColumnMap(ctx, s.view, span.NewURI(params.TextDocument.URI)) if err != nil { return "", jsonrpc2.NewErrorf(jsonrpc2.CodeInternalError, "file not found") } @@ -246,7 +246,7 @@ func (s *server) DidChange(ctx context.Context, params *protocol.DidChangeTextDo } text = change.Text } - return s.cacheAndDiagnose(ctx, span.URI(params.TextDocument.URI), text) + return s.cacheAndDiagnose(ctx, span.NewURI(params.TextDocument.URI), text) } func (s *server) WillSave(context.Context, *protocol.WillSaveTextDocumentParams) error { @@ -262,12 +262,12 @@ func (s *server) DidSave(context.Context, *protocol.DidSaveTextDocumentParams) e } func (s *server) DidClose(ctx context.Context, params *protocol.DidCloseTextDocumentParams) error { - s.setContent(ctx, span.URI(params.TextDocument.URI), nil) + s.setContent(ctx, span.NewURI(params.TextDocument.URI), nil) return nil } func (s *server) Completion(ctx context.Context, params *protocol.CompletionParams) (*protocol.CompletionList, error) { - f, m, err := newColumnMap(ctx, s.view, span.URI(params.TextDocument.URI)) + f, m, err := newColumnMap(ctx, s.view, span.NewURI(params.TextDocument.URI)) if err != nil { return nil, err } @@ -294,7 +294,7 @@ func (s *server) CompletionResolve(context.Context, *protocol.CompletionItem) (* } func (s *server) Hover(ctx context.Context, params *protocol.TextDocumentPositionParams) (*protocol.Hover, error) { - f, m, err := newColumnMap(ctx, s.view, span.URI(params.TextDocument.URI)) + f, m, err := newColumnMap(ctx, s.view, span.NewURI(params.TextDocument.URI)) if err != nil { return nil, err } @@ -333,7 +333,7 @@ func (s *server) Hover(ctx context.Context, params *protocol.TextDocumentPositio } func (s *server) SignatureHelp(ctx context.Context, params *protocol.TextDocumentPositionParams) (*protocol.SignatureHelp, error) { - f, m, err := newColumnMap(ctx, s.view, span.URI(params.TextDocument.URI)) + f, m, err := newColumnMap(ctx, s.view, span.NewURI(params.TextDocument.URI)) if err != nil { return nil, err } @@ -353,7 +353,7 @@ func (s *server) SignatureHelp(ctx context.Context, params *protocol.TextDocumen } func (s *server) Definition(ctx context.Context, params *protocol.TextDocumentPositionParams) ([]protocol.Location, error) { - f, m, err := newColumnMap(ctx, s.view, span.URI(params.TextDocument.URI)) + f, m, err := newColumnMap(ctx, s.view, span.NewURI(params.TextDocument.URI)) if err != nil { return nil, err } @@ -385,7 +385,7 @@ func (s *server) Definition(ctx context.Context, params *protocol.TextDocumentPo } func (s *server) TypeDefinition(ctx context.Context, params *protocol.TextDocumentPositionParams) ([]protocol.Location, error) { - f, m, err := newColumnMap(ctx, s.view, span.URI(params.TextDocument.URI)) + f, m, err := newColumnMap(ctx, s.view, span.NewURI(params.TextDocument.URI)) if err != nil { return nil, err } @@ -425,7 +425,7 @@ func (s *server) References(context.Context, *protocol.ReferenceParams) ([]proto } func (s *server) DocumentHighlight(ctx context.Context, params *protocol.TextDocumentPositionParams) ([]protocol.DocumentHighlight, error) { - f, m, err := newColumnMap(ctx, s.view, span.URI(params.TextDocument.URI)) + f, m, err := newColumnMap(ctx, s.view, span.NewURI(params.TextDocument.URI)) if err != nil { return nil, err } @@ -445,7 +445,7 @@ func (s *server) DocumentHighlight(ctx context.Context, params *protocol.TextDoc } func (s *server) DocumentSymbol(ctx context.Context, params *protocol.DocumentSymbolParams) ([]protocol.DocumentSymbol, error) { - f, m, err := newColumnMap(ctx, s.view, span.URI(params.TextDocument.URI)) + f, m, err := newColumnMap(ctx, s.view, span.NewURI(params.TextDocument.URI)) if err != nil { return nil, err } @@ -454,7 +454,7 @@ func (s *server) DocumentSymbol(ctx context.Context, params *protocol.DocumentSy } func (s *server) CodeAction(ctx context.Context, params *protocol.CodeActionParams) ([]protocol.CodeAction, error) { - _, m, err := newColumnMap(ctx, s.view, span.URI(params.TextDocument.URI)) + _, m, err := newColumnMap(ctx, s.view, span.NewURI(params.TextDocument.URI)) if err != nil { return nil, err } @@ -509,7 +509,7 @@ func (s *server) Formatting(ctx context.Context, params *protocol.DocumentFormat } func (s *server) RangeFormatting(ctx context.Context, params *protocol.DocumentRangeFormattingParams) ([]protocol.TextEdit, error) { - _, m, err := newColumnMap(ctx, s.view, span.URI(params.TextDocument.URI)) + _, m, err := newColumnMap(ctx, s.view, span.NewURI(params.TextDocument.URI)) if err != nil { return nil, err } diff --git a/internal/span/uri.go b/internal/span/uri.go index 55b3d37065..33755cfe02 100644 --- a/internal/span/uri.go +++ b/internal/span/uri.go @@ -45,6 +45,9 @@ func filename(uri URI) (string, error) { // NewURI returns a span URI for the string. // It will attempt to detect if the string is a file path or uri. func NewURI(s string) URI { + if u, err := url.PathUnescape(s); err == nil { + s = u + } if strings.HasPrefix(s, fileScheme+"://") { return URI(s) }