2018-12-05 15:00:36 -07:00
|
|
|
// Copyright 2018 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 cache
|
|
|
|
|
|
|
|
import (
|
|
|
|
"go/token"
|
2019-03-27 07:25:30 -06:00
|
|
|
"path/filepath"
|
|
|
|
"strings"
|
2018-12-05 15:00:36 -07:00
|
|
|
|
|
|
|
"golang.org/x/tools/internal/lsp/source"
|
2019-02-19 19:11:15 -07:00
|
|
|
"golang.org/x/tools/internal/span"
|
2018-12-05 15:00:36 -07:00
|
|
|
)
|
|
|
|
|
2019-05-03 22:04:18 -06:00
|
|
|
// viewFile extends source.File with helper methods for the view package.
|
|
|
|
type viewFile interface {
|
|
|
|
source.File
|
2019-05-23 13:03:11 -06:00
|
|
|
|
2019-05-03 22:04:18 -06:00
|
|
|
filename() string
|
|
|
|
addURI(uri span.URI) int
|
|
|
|
}
|
|
|
|
|
|
|
|
// fileBase holds the common functionality for all files.
|
|
|
|
// It is intended to be embedded in the file implementations
|
|
|
|
type fileBase struct {
|
|
|
|
uris []span.URI
|
|
|
|
fname string
|
2019-06-21 15:00:02 -06:00
|
|
|
kind source.FileKind
|
2019-03-27 07:25:30 -06:00
|
|
|
|
2019-06-13 13:55:53 -06:00
|
|
|
view *view
|
2019-05-03 22:04:18 -06:00
|
|
|
}
|
|
|
|
|
2019-10-15 16:07:52 -06:00
|
|
|
func dir(filename string) string {
|
|
|
|
return strings.ToLower(filepath.Dir(filename))
|
|
|
|
}
|
|
|
|
|
2019-03-27 07:25:30 -06:00
|
|
|
func basename(filename string) string {
|
|
|
|
return strings.ToLower(filepath.Base(filename))
|
|
|
|
}
|
|
|
|
|
2019-05-03 22:04:18 -06:00
|
|
|
func (f *fileBase) URI() span.URI {
|
2019-03-27 07:25:30 -06:00
|
|
|
return f.uris[0]
|
2019-02-19 19:11:15 -07:00
|
|
|
}
|
|
|
|
|
2019-09-27 11:17:59 -06:00
|
|
|
func (f *fileBase) Kind() source.FileKind {
|
|
|
|
return f.kind
|
|
|
|
}
|
|
|
|
|
2019-05-03 22:04:18 -06:00
|
|
|
func (f *fileBase) filename() string {
|
|
|
|
return f.fname
|
|
|
|
}
|
|
|
|
|
2019-04-17 16:21:47 -06:00
|
|
|
// View returns the view associated with the file.
|
2019-05-03 22:04:18 -06:00
|
|
|
func (f *fileBase) View() source.View {
|
2019-04-17 16:21:47 -06:00
|
|
|
return f.view
|
|
|
|
}
|
|
|
|
|
2019-05-17 08:51:19 -06:00
|
|
|
func (f *fileBase) FileSet() *token.FileSet {
|
|
|
|
return f.view.Session().Cache().FileSet()
|
2018-12-05 15:00:36 -07:00
|
|
|
}
|