1
0
mirror of https://github.com/golang/go synced 2024-10-01 07:38:32 -06:00
go/internal/lsp/cache/external.go
Ian Cottrell 75713da896 internal/lsp: add a file system abstraction
Change-Id: Ie42835b835ed22fddbba187ab10d8c31019ff008
Reviewed-on: https://go-review.googlesource.com/c/tools/+/178097
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-05-24 13:48:47 +00:00

30 lines
691 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 (
"io/ioutil"
"golang.org/x/tools/internal/lsp/source"
"golang.org/x/tools/internal/span"
)
// nativeFileSystem implements FileSystem reading from the normal os file system.
type nativeFileSystem struct{}
func (nativeFileSystem) ReadFile(uri span.URI) *source.FileContent {
r := &source.FileContent{URI: uri}
filename, err := uri.Filename()
if err != nil {
r.Error = err
return r
}
r.Data, r.Error = ioutil.ReadFile(filename)
if r.Error != nil {
r.Hash = hashContents(r.Data)
}
return r
}