1
0
mirror of https://github.com/golang/go synced 2024-11-18 22:24:50 -07:00
go/internal/lsp/cache/file.go
Rebecca Stambler 0bbdf54eff internal/lsp: modify approach to watching changed files
This change modifies the invalidContent function to take a file change
type. This allows us to eliminate the separate invalidateMetadata
function. The logic of watching changed files is then further pushed
into the caching layer.

Updates golang/go#34218

Change-Id: Id31b3931c45ec408b6e7b4a362e00f9091ba4f70
Reviewed-on: https://go-review.googlesource.com/c/tools/+/201221
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-10-22 21:33:45 +00:00

62 lines
1.2 KiB
Go

// 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"
"path/filepath"
"strings"
"golang.org/x/tools/internal/lsp/source"
"golang.org/x/tools/internal/span"
)
// viewFile extends source.File with helper methods for the view package.
type viewFile interface {
source.File
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
kind source.FileKind
view *view
}
func dir(filename string) string {
return strings.ToLower(filepath.Dir(filename))
}
func basename(filename string) string {
return strings.ToLower(filepath.Base(filename))
}
func (f *fileBase) URI() span.URI {
return f.uris[0]
}
func (f *fileBase) Kind() source.FileKind {
return f.kind
}
func (f *fileBase) filename() string {
return f.fname
}
// View returns the view associated with the file.
func (f *fileBase) View() source.View {
return f.view
}
func (f *fileBase) FileSet() *token.FileSet {
return f.view.Session().Cache().FileSet()
}