1
0
mirror of https://github.com/golang/go synced 2024-11-18 16:44:43 -07:00

internal/lsp: don't show diagnostics for mod files

The Go file changes didn't actually check the file extensions for the
files the Go extension is receiving. This error was not noticed because
the VSCode extension doesn't yet actually send mod files to gopls yet,
but it will in its next release.

Fixes golang/go#32178

Change-Id: Ia04d0a92ce7df13fcf4c601421bc000d69855f6d
Reviewed-on: https://go-review.googlesource.com/c/tools/+/178679
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
This commit is contained in:
Rebecca Stambler 2019-05-23 12:08:20 -04:00
parent 521d6ed310
commit 38d8bcfa38
3 changed files with 19 additions and 13 deletions

View File

@ -15,11 +15,10 @@ import (
"golang.org/x/tools/go/analysis"
"golang.org/x/tools/go/packages"
"golang.org/x/tools/internal/lsp/source"
"golang.org/x/tools/internal/span"
)
func (v *view) parse(ctx context.Context, file source.File) ([]packages.Error, error) {
func (v *view) parse(ctx context.Context, f *goFile) ([]packages.Error, error) {
v.mcache.mu.Lock()
defer v.mcache.mu.Unlock()
@ -28,11 +27,6 @@ func (v *view) parse(ctx context.Context, file source.File) ([]packages.Error, e
return nil, err
}
f, ok := file.(*goFile)
if !ok {
return nil, fmt.Errorf("not a go file: %v", file.URI())
}
// If the package for the file has not been invalidated by the application
// of the pending changes, there is no need to continue.
if f.isPopulated() {

View File

@ -6,10 +6,12 @@ package cache
import (
"context"
"fmt"
"go/ast"
"go/parser"
"go/types"
"os"
"path/filepath"
"sync"
"golang.org/x/tools/go/packages"
@ -327,12 +329,21 @@ func (v *view) getFile(uri span.URI) (viewFile, error) {
if err != nil {
return nil, err
}
f := &goFile{
fileBase: fileBase{
view: v,
fname: filename,
},
var f *goFile
switch ext := filepath.Ext(filename); ext {
case ".go":
f = &goFile{
fileBase: fileBase{
view: v,
fname: filename,
},
}
case ".mod":
return nil, fmt.Errorf("mod files are not yet supported")
default:
return nil, fmt.Errorf("unsupported file extension: %s", ext)
}
v.mapFile(uri, f)
return f, nil
}

View File

@ -56,9 +56,10 @@ func Diagnostics(ctx context.Context, v View, uri span.URI) (map[span.URI][]Diag
if err != nil {
return singleDiagnostic(uri, "no file found for %s", uri), nil
}
// For non-Go files, don't return any diagnostics.
gof, ok := f.(GoFile)
if !ok {
return singleDiagnostic(uri, "%s is not a go file", uri), nil
return nil, nil
}
pkg := gof.GetPackage(ctx)
if pkg == nil {