2019-04-17 13:37:20 -06:00
|
|
|
// 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"
|
|
|
|
|
|
|
|
"golang.org/x/tools/internal/lsp/protocol"
|
|
|
|
"golang.org/x/tools/internal/lsp/source"
|
|
|
|
"golang.org/x/tools/internal/span"
|
2019-08-06 13:13:11 -06:00
|
|
|
errors "golang.org/x/xerrors"
|
2019-04-17 13:37:20 -06:00
|
|
|
)
|
|
|
|
|
2019-08-16 11:49:17 -06:00
|
|
|
func getGoFile(ctx context.Context, view source.View, uri span.URI) (source.GoFile, error) {
|
|
|
|
f, err := view.GetFile(ctx, uri)
|
2019-04-17 13:37:20 -06:00
|
|
|
if err != nil {
|
2019-08-16 11:49:17 -06:00
|
|
|
return nil, err
|
2019-04-17 13:37:20 -06:00
|
|
|
}
|
2019-08-16 11:49:17 -06:00
|
|
|
gof, ok := f.(source.GoFile)
|
|
|
|
if !ok {
|
|
|
|
return nil, errors.Errorf("%s is not a Go file", uri)
|
2019-07-11 19:05:55 -06:00
|
|
|
}
|
2019-08-16 11:49:17 -06:00
|
|
|
return gof, nil
|
2019-04-17 13:37:20 -06:00
|
|
|
}
|
2019-05-03 22:04:18 -06:00
|
|
|
|
2019-08-16 11:49:17 -06:00
|
|
|
func getMapper(ctx context.Context, f source.File) (*protocol.ColumnMapper, error) {
|
|
|
|
data, _, err := f.Handle(ctx).Read(ctx)
|
2019-05-03 22:04:18 -06:00
|
|
|
if err != nil {
|
2019-08-16 11:49:17 -06:00
|
|
|
return nil, err
|
2019-05-03 22:04:18 -06:00
|
|
|
}
|
2019-08-16 11:49:17 -06:00
|
|
|
tok, err := f.GetToken(ctx)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
2019-05-03 22:04:18 -06:00
|
|
|
}
|
2019-08-16 11:49:17 -06:00
|
|
|
return protocol.NewColumnMapper(f.URI(), f.URI().Filename(), f.FileSet(), tok, data), nil
|
2019-05-03 22:04:18 -06:00
|
|
|
}
|