mirror of
https://github.com/golang/go
synced 2024-11-19 00:14:39 -07:00
08e0b306e8
Also add a new rendering mode, and clean up the plain text one. Then use it to add an info page to to the server in debug mode. Change-Id: Ifa66a75260965d0e46e874200203ebbc4490e424 Reviewed-on: https://go-review.googlesource.com/c/tools/+/179497 Reviewed-by: Rebecca Stambler <rstambler@golang.org>
45 lines
1.1 KiB
Go
45 lines
1.1 KiB
Go
// Copyright 2019 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 lsp
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"golang.org/x/tools/internal/lsp/protocol"
|
|
"golang.org/x/tools/internal/lsp/source"
|
|
"golang.org/x/tools/internal/span"
|
|
)
|
|
|
|
func getSourceFile(ctx context.Context, v source.View, uri span.URI) (source.File, *protocol.ColumnMapper, error) {
|
|
f, err := v.GetFile(ctx, uri)
|
|
if err != nil {
|
|
return nil, nil, err
|
|
}
|
|
filename, err := f.URI().Filename()
|
|
if err != nil {
|
|
return nil, nil, err
|
|
}
|
|
fc := f.Content(ctx)
|
|
if fc.Error != nil {
|
|
return nil, nil, fc.Error
|
|
}
|
|
m := protocol.NewColumnMapper(f.URI(), filename, f.FileSet(), f.GetToken(ctx), fc.Data)
|
|
|
|
return f, m, nil
|
|
}
|
|
|
|
func getGoFile(ctx context.Context, v source.View, uri span.URI) (source.GoFile, *protocol.ColumnMapper, error) {
|
|
f, m, err := getSourceFile(ctx, v, uri)
|
|
if err != nil {
|
|
return nil, nil, err
|
|
}
|
|
gof, ok := f.(source.GoFile)
|
|
if !ok {
|
|
return nil, nil, fmt.Errorf("not a Go file %v", f.URI())
|
|
}
|
|
return gof, m, nil
|
|
}
|