1
0
mirror of https://github.com/golang/go synced 2024-11-19 06:34:42 -07:00
go/internal/lsp/cache/cache.go
Ian Cottrell 2c0ae70061 internal/lsp: add file watching and use it to trigger invalidations
Change-Id: I6148539509364655e7d42044b73789870d30fbb6
Reviewed-on: https://go-review.googlesource.com/c/tools/+/178161
Run-TryBot: Ian Cottrell <iancottrell@google.com>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-05-24 14:03:12 +00:00

47 lines
963 B
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 cache
import (
"crypto/sha1"
"fmt"
"go/token"
"golang.org/x/tools/internal/lsp/source"
"golang.org/x/tools/internal/lsp/xlog"
"golang.org/x/tools/internal/span"
)
func New() source.Cache {
return &cache{
fset: token.NewFileSet(),
}
}
type cache struct {
nativeFileSystem
fset *token.FileSet
}
func (c *cache) NewSession(log xlog.Logger) source.Session {
return &session{
cache: c,
log: log,
overlays: make(map[span.URI]*source.FileContent),
filesWatchMap: NewWatchMap(),
}
}
func (c *cache) FileSet() *token.FileSet {
return c.fset
}
func hashContents(contents []byte) string {
// TODO: consider whether sha1 is the best choice here
// This hash is used for internal identity detection only
return fmt.Sprintf("%x", sha1.Sum(contents))
}