1
0
mirror of https://github.com/golang/go synced 2024-10-01 05:28:33 -06:00
go/internal/lsp/util.go

26 lines
589 B
Go
Raw Normal View History

// 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/source"
"golang.org/x/tools/internal/span"
errors "golang.org/x/xerrors"
)
func getGoFile(ctx context.Context, view source.View, uri span.URI) (source.GoFile, error) {
f, err := view.GetFile(ctx, uri)
if err != nil {
return nil, err
}
gof, ok := f.(source.GoFile)
if !ok {
return nil, errors.Errorf("%s is not a Go file", uri)
}
return gof, nil
}