2019-06-12 07:55:08 -06:00
|
|
|
// Copyright 2019 The Go Authors. All rights reserved.
|
2019-04-16 13:47:48 -06:00
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
2019-09-17 09:10:48 -06:00
|
|
|
// Package tests exports functionality to be used across a variety of gopls tests.
|
2019-04-16 13:47:48 -06:00
|
|
|
package tests
|
|
|
|
|
|
|
|
import (
|
2019-09-26 10:54:25 -06:00
|
|
|
"bytes"
|
2019-04-16 13:47:48 -06:00
|
|
|
"context"
|
2019-04-09 20:23:02 -06:00
|
|
|
"flag"
|
2019-09-26 10:54:25 -06:00
|
|
|
"fmt"
|
2019-04-16 13:47:48 -06:00
|
|
|
"go/ast"
|
|
|
|
"go/token"
|
|
|
|
"io/ioutil"
|
|
|
|
"path/filepath"
|
2019-05-01 17:16:03 -06:00
|
|
|
"sort"
|
2019-04-16 13:47:48 -06:00
|
|
|
"strings"
|
2019-09-09 22:36:39 -06:00
|
|
|
"sync"
|
2019-04-16 13:47:48 -06:00
|
|
|
"testing"
|
|
|
|
|
2019-07-07 16:25:19 -06:00
|
|
|
"golang.org/x/tools/go/expect"
|
2019-04-16 13:47:48 -06:00
|
|
|
"golang.org/x/tools/go/packages"
|
|
|
|
"golang.org/x/tools/go/packages/packagestest"
|
2019-08-14 18:12:18 -06:00
|
|
|
"golang.org/x/tools/internal/lsp/protocol"
|
2019-04-16 13:47:48 -06:00
|
|
|
"golang.org/x/tools/internal/lsp/source"
|
|
|
|
"golang.org/x/tools/internal/span"
|
2019-05-01 17:16:03 -06:00
|
|
|
"golang.org/x/tools/internal/txtar"
|
2019-04-16 13:47:48 -06:00
|
|
|
)
|
|
|
|
|
2019-04-09 20:23:02 -06:00
|
|
|
const (
|
2019-05-01 17:16:03 -06:00
|
|
|
overlayFileSuffix = ".overlay"
|
|
|
|
goldenFileSuffix = ".golden"
|
|
|
|
inFileSuffix = ".in"
|
|
|
|
testModule = "golang.org/x/tools/internal/lsp"
|
2019-04-09 20:23:02 -06:00
|
|
|
)
|
|
|
|
|
2019-09-23 21:12:28 -06:00
|
|
|
var UpdateGolden = flag.Bool("golden", false, "Update golden files")
|
2019-04-09 20:23:02 -06:00
|
|
|
|
2019-04-16 13:47:48 -06:00
|
|
|
type Diagnostics map[span.URI][]source.Diagnostic
|
|
|
|
type CompletionItems map[token.Pos]*source.CompletionItem
|
2019-06-17 21:56:06 -06:00
|
|
|
type Completions map[span.Span]Completion
|
2019-04-28 21:19:54 -06:00
|
|
|
type CompletionSnippets map[span.Span]CompletionSnippet
|
2019-09-17 09:10:48 -06:00
|
|
|
type UnimportedCompletions map[span.Span]Completion
|
|
|
|
type DeepCompletions map[span.Span]Completion
|
|
|
|
type FuzzyCompletions map[span.Span]Completion
|
2019-09-26 05:59:06 -06:00
|
|
|
type CaseSensitiveCompletions map[span.Span]Completion
|
2019-09-17 09:10:48 -06:00
|
|
|
type RankCompletions map[span.Span]Completion
|
2019-08-28 19:48:29 -06:00
|
|
|
type FoldingRanges []span.Span
|
2019-04-22 16:15:39 -06:00
|
|
|
type Formats []span.Span
|
2019-05-31 20:42:59 -06:00
|
|
|
type Imports []span.Span
|
2019-09-04 11:16:09 -06:00
|
|
|
type SuggestedFixes []span.Span
|
2019-04-16 13:47:48 -06:00
|
|
|
type Definitions map[span.Span]Definition
|
2019-10-28 13:16:55 -06:00
|
|
|
type Implementationses map[span.Span]Implementations
|
2019-04-16 13:47:48 -06:00
|
|
|
type Highlights map[string][]span.Span
|
2019-06-07 08:04:22 -06:00
|
|
|
type References map[span.Span][]span.Span
|
2019-06-18 08:23:37 -06:00
|
|
|
type Renames map[span.Span]string
|
2019-08-22 11:31:03 -06:00
|
|
|
type PrepareRenames map[span.Span]*source.PrepareItem
|
2019-09-05 16:54:05 -06:00
|
|
|
type Symbols map[span.URI][]protocol.DocumentSymbol
|
|
|
|
type SymbolsChildren map[string][]protocol.DocumentSymbol
|
2019-06-28 19:27:41 -06:00
|
|
|
type Signatures map[span.Span]*source.SignatureInformation
|
2019-04-24 09:33:45 -06:00
|
|
|
type Links map[span.URI][]Link
|
2019-04-16 13:47:48 -06:00
|
|
|
|
|
|
|
type Data struct {
|
2019-09-26 05:59:06 -06:00
|
|
|
Config packages.Config
|
|
|
|
Exported *packagestest.Exported
|
|
|
|
Diagnostics Diagnostics
|
|
|
|
CompletionItems CompletionItems
|
|
|
|
Completions Completions
|
|
|
|
CompletionSnippets CompletionSnippets
|
|
|
|
UnimportedCompletions UnimportedCompletions
|
|
|
|
DeepCompletions DeepCompletions
|
|
|
|
FuzzyCompletions FuzzyCompletions
|
|
|
|
CaseSensitiveCompletions CaseSensitiveCompletions
|
|
|
|
RankCompletions RankCompletions
|
|
|
|
FoldingRanges FoldingRanges
|
|
|
|
Formats Formats
|
|
|
|
Imports Imports
|
|
|
|
SuggestedFixes SuggestedFixes
|
|
|
|
Definitions Definitions
|
2019-10-28 13:16:55 -06:00
|
|
|
Implementationses Implementationses
|
2019-09-26 05:59:06 -06:00
|
|
|
Highlights Highlights
|
|
|
|
References References
|
|
|
|
Renames Renames
|
|
|
|
PrepareRenames PrepareRenames
|
|
|
|
Symbols Symbols
|
|
|
|
symbolsChildren SymbolsChildren
|
|
|
|
Signatures Signatures
|
|
|
|
Links Links
|
2019-04-09 20:23:02 -06:00
|
|
|
|
|
|
|
t testing.TB
|
|
|
|
fragments map[string]string
|
|
|
|
dir string
|
2019-05-01 17:16:03 -06:00
|
|
|
golden map[string]*Golden
|
2019-09-09 22:36:39 -06:00
|
|
|
|
|
|
|
mappersMu sync.Mutex
|
|
|
|
mappers map[span.URI]*protocol.ColumnMapper
|
2019-04-16 13:47:48 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
type Tests interface {
|
2019-09-26 11:56:23 -06:00
|
|
|
Diagnostics(*testing.T, span.URI, []source.Diagnostic)
|
|
|
|
Completion(*testing.T, span.Span, Completion, CompletionItems)
|
|
|
|
CompletionSnippet(*testing.T, span.Span, CompletionSnippet, bool, CompletionItems)
|
|
|
|
UnimportedCompletion(*testing.T, span.Span, Completion, CompletionItems)
|
|
|
|
DeepCompletion(*testing.T, span.Span, Completion, CompletionItems)
|
|
|
|
FuzzyCompletion(*testing.T, span.Span, Completion, CompletionItems)
|
|
|
|
CaseSensitiveCompletion(*testing.T, span.Span, Completion, CompletionItems)
|
|
|
|
RankCompletion(*testing.T, span.Span, Completion, CompletionItems)
|
|
|
|
FoldingRange(*testing.T, span.Span)
|
|
|
|
Format(*testing.T, span.Span)
|
|
|
|
Import(*testing.T, span.Span)
|
|
|
|
SuggestedFix(*testing.T, span.Span)
|
|
|
|
Definition(*testing.T, span.Span, Definition)
|
2019-10-28 13:16:55 -06:00
|
|
|
Implementation(*testing.T, span.Span, Implementations)
|
2019-09-26 11:56:23 -06:00
|
|
|
Highlight(*testing.T, string, []span.Span)
|
2019-10-19 15:26:56 -06:00
|
|
|
References(*testing.T, span.Span, []span.Span)
|
2019-09-26 11:56:23 -06:00
|
|
|
Rename(*testing.T, span.Span, string)
|
|
|
|
PrepareRename(*testing.T, span.Span, *source.PrepareItem)
|
2019-10-27 11:41:48 -06:00
|
|
|
Symbols(*testing.T, span.URI, []protocol.DocumentSymbol)
|
2019-09-26 11:56:23 -06:00
|
|
|
SignatureHelp(*testing.T, span.Span, *source.SignatureInformation)
|
|
|
|
Link(*testing.T, span.URI, []Link)
|
2019-04-16 13:47:48 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
type Definition struct {
|
2019-05-15 15:58:16 -06:00
|
|
|
Name string
|
|
|
|
IsType bool
|
|
|
|
OnlyHover bool
|
2019-08-26 22:26:45 -06:00
|
|
|
Src, Def span.Span
|
2019-04-16 13:47:48 -06:00
|
|
|
}
|
|
|
|
|
2019-10-28 13:16:55 -06:00
|
|
|
type Implementations struct {
|
|
|
|
Src span.Span
|
|
|
|
Implementations []span.Span
|
|
|
|
}
|
|
|
|
|
2019-06-17 21:56:06 -06:00
|
|
|
type CompletionTestType int
|
|
|
|
|
|
|
|
const (
|
2019-09-17 09:10:48 -06:00
|
|
|
// Default runs the standard completion tests.
|
|
|
|
CompletionDefault = CompletionTestType(iota)
|
2019-06-17 21:56:06 -06:00
|
|
|
|
2019-09-17 09:10:48 -06:00
|
|
|
// Unimported tests the autocompletion of unimported packages.
|
|
|
|
CompletionUnimported
|
|
|
|
|
|
|
|
// Deep tests deep completion.
|
|
|
|
CompletionDeep
|
|
|
|
|
|
|
|
// Fuzzy tests deep completion and fuzzy matching.
|
|
|
|
CompletionFuzzy
|
|
|
|
|
2019-09-26 05:59:06 -06:00
|
|
|
// CaseSensitive tests case sensitive completion
|
|
|
|
CompletionCaseSensitve
|
|
|
|
|
2019-09-17 09:10:48 -06:00
|
|
|
// CompletionRank candidates in test must be valid and in the right relative order.
|
|
|
|
CompletionRank
|
2019-06-17 21:56:06 -06:00
|
|
|
)
|
|
|
|
|
|
|
|
type Completion struct {
|
|
|
|
CompletionItems []token.Pos
|
|
|
|
}
|
|
|
|
|
2019-04-28 21:19:54 -06:00
|
|
|
type CompletionSnippet struct {
|
|
|
|
CompletionItem token.Pos
|
|
|
|
PlainSnippet string
|
|
|
|
PlaceholderSnippet string
|
|
|
|
}
|
|
|
|
|
2019-04-24 09:33:45 -06:00
|
|
|
type Link struct {
|
2019-07-07 16:25:19 -06:00
|
|
|
Src span.Span
|
|
|
|
Target string
|
|
|
|
NotePosition token.Position
|
2019-04-24 09:33:45 -06:00
|
|
|
}
|
|
|
|
|
2019-05-01 17:16:03 -06:00
|
|
|
type Golden struct {
|
|
|
|
Filename string
|
|
|
|
Archive *txtar.Archive
|
|
|
|
Modified bool
|
|
|
|
}
|
|
|
|
|
2019-07-10 19:11:23 -06:00
|
|
|
func Context(t testing.TB) context.Context {
|
|
|
|
return context.Background()
|
|
|
|
}
|
|
|
|
|
2019-09-17 09:10:48 -06:00
|
|
|
func DefaultOptions() source.Options {
|
|
|
|
o := source.DefaultOptions
|
|
|
|
o.SupportedCodeActions = map[source.FileKind]map[protocol.CodeActionKind]bool{
|
|
|
|
source.Go: {
|
|
|
|
protocol.SourceOrganizeImports: true,
|
|
|
|
protocol.QuickFix: true,
|
|
|
|
},
|
|
|
|
source.Mod: {},
|
|
|
|
source.Sum: {},
|
|
|
|
}
|
|
|
|
o.HoverKind = source.SynopsisDocumentation
|
|
|
|
o.InsertTextFormat = protocol.SnippetTextFormat
|
|
|
|
return o
|
|
|
|
}
|
|
|
|
|
2019-04-16 13:47:48 -06:00
|
|
|
func Load(t testing.TB, exporter packagestest.Exporter, dir string) *Data {
|
|
|
|
t.Helper()
|
|
|
|
|
|
|
|
data := &Data{
|
2019-09-26 05:59:06 -06:00
|
|
|
Diagnostics: make(Diagnostics),
|
|
|
|
CompletionItems: make(CompletionItems),
|
|
|
|
Completions: make(Completions),
|
|
|
|
CompletionSnippets: make(CompletionSnippets),
|
|
|
|
UnimportedCompletions: make(UnimportedCompletions),
|
|
|
|
DeepCompletions: make(DeepCompletions),
|
|
|
|
FuzzyCompletions: make(FuzzyCompletions),
|
|
|
|
RankCompletions: make(RankCompletions),
|
|
|
|
CaseSensitiveCompletions: make(CaseSensitiveCompletions),
|
|
|
|
Definitions: make(Definitions),
|
2019-10-28 13:16:55 -06:00
|
|
|
Implementationses: make(Implementationses),
|
2019-09-26 05:59:06 -06:00
|
|
|
Highlights: make(Highlights),
|
|
|
|
References: make(References),
|
|
|
|
Renames: make(Renames),
|
|
|
|
PrepareRenames: make(PrepareRenames),
|
|
|
|
Symbols: make(Symbols),
|
|
|
|
symbolsChildren: make(SymbolsChildren),
|
|
|
|
Signatures: make(Signatures),
|
|
|
|
Links: make(Links),
|
2019-04-09 20:23:02 -06:00
|
|
|
|
|
|
|
t: t,
|
|
|
|
dir: dir,
|
|
|
|
fragments: map[string]string{},
|
2019-05-01 17:16:03 -06:00
|
|
|
golden: map[string]*Golden{},
|
2019-09-09 22:36:39 -06:00
|
|
|
mappers: map[span.URI]*protocol.ColumnMapper{},
|
2019-04-16 13:47:48 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
files := packagestest.MustCopyFileTree(dir)
|
|
|
|
overlays := map[string][]byte{}
|
|
|
|
for fragment, operation := range files {
|
2019-05-01 17:16:03 -06:00
|
|
|
if trimmed := strings.TrimSuffix(fragment, goldenFileSuffix); trimmed != fragment {
|
2019-04-09 20:23:02 -06:00
|
|
|
delete(files, fragment)
|
2019-05-01 17:16:03 -06:00
|
|
|
goldFile := filepath.Join(dir, fragment)
|
|
|
|
archive, err := txtar.ParseFile(goldFile)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("could not read golden file %v: %v", fragment, err)
|
|
|
|
}
|
|
|
|
data.golden[trimmed] = &Golden{
|
|
|
|
Filename: goldFile,
|
|
|
|
Archive: archive,
|
|
|
|
}
|
|
|
|
} else if trimmed := strings.TrimSuffix(fragment, inFileSuffix); trimmed != fragment {
|
2019-04-16 13:47:48 -06:00
|
|
|
delete(files, fragment)
|
|
|
|
files[trimmed] = operation
|
2019-05-01 17:16:03 -06:00
|
|
|
} else if index := strings.Index(fragment, overlayFileSuffix); index >= 0 {
|
2019-04-16 13:47:48 -06:00
|
|
|
delete(files, fragment)
|
2019-05-01 17:16:03 -06:00
|
|
|
partial := fragment[:index] + fragment[index+len(overlayFileSuffix):]
|
2019-04-16 13:47:48 -06:00
|
|
|
contents, err := ioutil.ReadFile(filepath.Join(dir, fragment))
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
overlays[partial] = contents
|
|
|
|
}
|
|
|
|
}
|
|
|
|
modules := []packagestest.Module{
|
|
|
|
{
|
2019-04-09 20:23:02 -06:00
|
|
|
Name: testModule,
|
2019-04-16 13:47:48 -06:00
|
|
|
Files: files,
|
|
|
|
Overlay: overlays,
|
|
|
|
},
|
2019-10-04 13:38:18 -06:00
|
|
|
{
|
|
|
|
Name: "example.com/extramodule",
|
|
|
|
Files: map[string]interface{}{
|
|
|
|
"pkg/x.go": "package pkg\n",
|
|
|
|
},
|
|
|
|
},
|
2019-04-16 13:47:48 -06:00
|
|
|
}
|
|
|
|
data.Exported = packagestest.Export(t, exporter, modules)
|
2019-09-17 09:10:48 -06:00
|
|
|
for fragment := range files {
|
2019-04-09 20:23:02 -06:00
|
|
|
filename := data.Exported.File(testModule, fragment)
|
|
|
|
data.fragments[filename] = fragment
|
|
|
|
}
|
2019-10-18 15:24:26 -06:00
|
|
|
|
|
|
|
// Turn off go/packages debug logging.
|
|
|
|
data.Exported.Config.Logf = nil
|
|
|
|
data.Config.Logf = nil
|
2019-04-16 13:47:48 -06:00
|
|
|
|
|
|
|
// Merge the exported.Config with the view.Config.
|
|
|
|
data.Config = *data.Exported.Config
|
|
|
|
data.Config.Fset = token.NewFileSet()
|
2019-07-10 19:11:23 -06:00
|
|
|
data.Config.Context = Context(nil)
|
2019-04-16 13:47:48 -06:00
|
|
|
data.Config.ParseFile = func(fset *token.FileSet, filename string, src []byte) (*ast.File, error) {
|
2019-06-04 20:14:37 -06:00
|
|
|
panic("ParseFile should not be called")
|
2019-04-16 13:47:48 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
// Do a first pass to collect special markers for completion.
|
|
|
|
if err := data.Exported.Expect(map[string]interface{}{
|
2019-08-06 16:51:17 -06:00
|
|
|
"item": func(name string, r packagestest.Range, _ []string) {
|
2019-04-16 13:47:48 -06:00
|
|
|
data.Exported.Mark(name, r)
|
|
|
|
},
|
|
|
|
}); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Collect any data that needs to be used by subsequent tests.
|
|
|
|
if err := data.Exported.Expect(map[string]interface{}{
|
2019-10-28 13:16:55 -06:00
|
|
|
"diag": data.collectDiagnostics,
|
|
|
|
"item": data.collectCompletionItems,
|
|
|
|
"complete": data.collectCompletions(CompletionDefault),
|
|
|
|
"unimported": data.collectCompletions(CompletionUnimported),
|
|
|
|
"deep": data.collectCompletions(CompletionDeep),
|
|
|
|
"fuzzy": data.collectCompletions(CompletionFuzzy),
|
|
|
|
"casesensitive": data.collectCompletions(CompletionCaseSensitve),
|
|
|
|
"rank": data.collectCompletions(CompletionRank),
|
|
|
|
"snippet": data.collectCompletionSnippets,
|
|
|
|
"fold": data.collectFoldingRanges,
|
|
|
|
"format": data.collectFormats,
|
|
|
|
"import": data.collectImports,
|
|
|
|
"godef": data.collectDefinitions,
|
|
|
|
"implementations": data.collectImplementations,
|
|
|
|
"typdef": data.collectTypeDefinitions,
|
|
|
|
"hover": data.collectHoverDefinitions,
|
|
|
|
"highlight": data.collectHighlights,
|
|
|
|
"refs": data.collectReferences,
|
|
|
|
"rename": data.collectRenames,
|
|
|
|
"prepare": data.collectPrepareRenames,
|
|
|
|
"symbol": data.collectSymbols,
|
|
|
|
"signature": data.collectSignatures,
|
|
|
|
"link": data.collectLinks,
|
|
|
|
"suggestedfix": data.collectSuggestedFixes,
|
2019-04-16 13:47:48 -06:00
|
|
|
}); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
for _, symbols := range data.Symbols {
|
|
|
|
for i := range symbols {
|
|
|
|
children := data.symbolsChildren[symbols[i].Name]
|
|
|
|
symbols[i].Children = children
|
|
|
|
}
|
|
|
|
}
|
2019-05-15 15:58:16 -06:00
|
|
|
// Collect names for the entries that require golden files.
|
2019-05-01 17:16:03 -06:00
|
|
|
if err := data.Exported.Expect(map[string]interface{}{
|
|
|
|
"godef": data.collectDefinitionNames,
|
2019-05-15 15:58:16 -06:00
|
|
|
"hover": data.collectDefinitionNames,
|
2019-05-01 17:16:03 -06:00
|
|
|
}); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2019-04-16 13:47:48 -06:00
|
|
|
return data
|
|
|
|
}
|
|
|
|
|
|
|
|
func Run(t *testing.T, tests Tests, data *Data) {
|
|
|
|
t.Helper()
|
2019-09-26 10:54:25 -06:00
|
|
|
checkData(t, data)
|
2019-09-17 09:10:48 -06:00
|
|
|
|
2019-04-16 13:47:48 -06:00
|
|
|
t.Run("Completion", func(t *testing.T) {
|
|
|
|
t.Helper()
|
2019-09-26 11:56:23 -06:00
|
|
|
for src, test := range data.Completions {
|
2019-09-26 23:06:08 -06:00
|
|
|
t.Run(spanName(src), func(t *testing.T) {
|
|
|
|
t.Helper()
|
|
|
|
tests.Completion(t, src, test, data.CompletionItems)
|
|
|
|
})
|
2019-09-26 11:56:23 -06:00
|
|
|
}
|
2019-09-17 09:10:48 -06:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("CompletionSnippets", func(t *testing.T) {
|
|
|
|
t.Helper()
|
2019-09-26 11:56:23 -06:00
|
|
|
for _, placeholders := range []bool{true, false} {
|
|
|
|
for src, expected := range data.CompletionSnippets {
|
2019-09-26 23:06:08 -06:00
|
|
|
name := spanName(src)
|
|
|
|
if placeholders {
|
|
|
|
name += "_placeholders"
|
|
|
|
}
|
|
|
|
t.Run(name, func(t *testing.T) {
|
|
|
|
t.Helper()
|
|
|
|
tests.CompletionSnippet(t, src, expected, placeholders, data.CompletionItems)
|
|
|
|
})
|
2019-09-26 11:56:23 -06:00
|
|
|
}
|
|
|
|
}
|
2019-09-17 09:10:48 -06:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("UnimportedCompletion", func(t *testing.T) {
|
|
|
|
t.Helper()
|
2019-09-26 11:56:23 -06:00
|
|
|
for src, test := range data.UnimportedCompletions {
|
2019-09-26 23:06:08 -06:00
|
|
|
t.Run(spanName(src), func(t *testing.T) {
|
|
|
|
t.Helper()
|
|
|
|
tests.UnimportedCompletion(t, src, test, data.CompletionItems)
|
|
|
|
})
|
2019-09-26 11:56:23 -06:00
|
|
|
}
|
2019-09-17 09:10:48 -06:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("DeepCompletion", func(t *testing.T) {
|
|
|
|
t.Helper()
|
2019-09-26 11:56:23 -06:00
|
|
|
for src, test := range data.DeepCompletions {
|
2019-09-26 23:06:08 -06:00
|
|
|
t.Run(spanName(src), func(t *testing.T) {
|
|
|
|
t.Helper()
|
|
|
|
tests.DeepCompletion(t, src, test, data.CompletionItems)
|
|
|
|
})
|
2019-09-26 11:56:23 -06:00
|
|
|
}
|
2019-09-17 09:10:48 -06:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("FuzzyCompletion", func(t *testing.T) {
|
|
|
|
t.Helper()
|
2019-09-26 11:56:23 -06:00
|
|
|
for src, test := range data.FuzzyCompletions {
|
2019-09-26 23:06:08 -06:00
|
|
|
t.Run(spanName(src), func(t *testing.T) {
|
|
|
|
t.Helper()
|
|
|
|
tests.FuzzyCompletion(t, src, test, data.CompletionItems)
|
|
|
|
})
|
2019-09-26 11:56:23 -06:00
|
|
|
}
|
2019-09-17 09:10:48 -06:00
|
|
|
})
|
|
|
|
|
2019-09-26 05:59:06 -06:00
|
|
|
t.Run("CaseSensitiveCompletion", func(t *testing.T) {
|
|
|
|
t.Helper()
|
2019-09-26 11:56:23 -06:00
|
|
|
for src, test := range data.CaseSensitiveCompletions {
|
2019-09-26 23:06:08 -06:00
|
|
|
t.Run(spanName(src), func(t *testing.T) {
|
|
|
|
t.Helper()
|
|
|
|
tests.CaseSensitiveCompletion(t, src, test, data.CompletionItems)
|
|
|
|
})
|
2019-09-26 11:56:23 -06:00
|
|
|
}
|
2019-09-26 05:59:06 -06:00
|
|
|
})
|
|
|
|
|
2019-09-17 09:10:48 -06:00
|
|
|
t.Run("RankCompletions", func(t *testing.T) {
|
|
|
|
t.Helper()
|
2019-09-26 11:56:23 -06:00
|
|
|
for src, test := range data.RankCompletions {
|
2019-09-26 23:06:08 -06:00
|
|
|
t.Run(spanName(src), func(t *testing.T) {
|
|
|
|
t.Helper()
|
|
|
|
tests.RankCompletion(t, src, test, data.CompletionItems)
|
|
|
|
})
|
2019-09-26 11:56:23 -06:00
|
|
|
}
|
2019-04-16 13:47:48 -06:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("Diagnostics", func(t *testing.T) {
|
|
|
|
t.Helper()
|
2019-09-26 11:56:23 -06:00
|
|
|
for uri, want := range data.Diagnostics {
|
2019-09-26 23:06:08 -06:00
|
|
|
t.Run(uriName(uri), func(t *testing.T) {
|
|
|
|
t.Helper()
|
|
|
|
tests.Diagnostics(t, uri, want)
|
|
|
|
})
|
2019-09-26 11:56:23 -06:00
|
|
|
}
|
2019-04-16 13:47:48 -06:00
|
|
|
})
|
|
|
|
|
2019-08-28 19:48:29 -06:00
|
|
|
t.Run("FoldingRange", func(t *testing.T) {
|
|
|
|
t.Helper()
|
2019-09-26 11:56:23 -06:00
|
|
|
for _, spn := range data.FoldingRanges {
|
2019-09-26 23:06:08 -06:00
|
|
|
t.Run(uriName(spn.URI()), func(t *testing.T) {
|
|
|
|
t.Helper()
|
|
|
|
tests.FoldingRange(t, spn)
|
|
|
|
})
|
2019-09-26 11:56:23 -06:00
|
|
|
}
|
2019-08-28 19:48:29 -06:00
|
|
|
})
|
|
|
|
|
2019-04-16 13:47:48 -06:00
|
|
|
t.Run("Format", func(t *testing.T) {
|
|
|
|
t.Helper()
|
2019-09-26 11:56:23 -06:00
|
|
|
for _, spn := range data.Formats {
|
2019-09-26 23:06:08 -06:00
|
|
|
t.Run(uriName(spn.URI()), func(t *testing.T) {
|
|
|
|
t.Helper()
|
|
|
|
tests.Format(t, spn)
|
|
|
|
})
|
2019-09-26 11:56:23 -06:00
|
|
|
}
|
2019-04-16 13:47:48 -06:00
|
|
|
})
|
|
|
|
|
2019-05-31 20:42:59 -06:00
|
|
|
t.Run("Import", func(t *testing.T) {
|
|
|
|
t.Helper()
|
2019-09-26 11:56:23 -06:00
|
|
|
for _, spn := range data.Imports {
|
2019-09-26 23:06:08 -06:00
|
|
|
t.Run(uriName(spn.URI()), func(t *testing.T) {
|
|
|
|
t.Helper()
|
|
|
|
tests.Import(t, spn)
|
|
|
|
})
|
2019-09-26 11:56:23 -06:00
|
|
|
}
|
2019-05-31 20:42:59 -06:00
|
|
|
})
|
|
|
|
|
2019-09-04 11:16:09 -06:00
|
|
|
t.Run("SuggestedFix", func(t *testing.T) {
|
|
|
|
t.Helper()
|
2019-09-26 11:56:23 -06:00
|
|
|
for _, spn := range data.SuggestedFixes {
|
2019-09-26 23:06:08 -06:00
|
|
|
t.Run(spanName(spn), func(t *testing.T) {
|
|
|
|
t.Helper()
|
|
|
|
tests.SuggestedFix(t, spn)
|
|
|
|
})
|
2019-09-26 11:56:23 -06:00
|
|
|
}
|
2019-09-04 11:16:09 -06:00
|
|
|
})
|
|
|
|
|
2019-04-27 20:45:06 -06:00
|
|
|
t.Run("Definition", func(t *testing.T) {
|
2019-04-16 13:47:48 -06:00
|
|
|
t.Helper()
|
2019-09-26 11:56:23 -06:00
|
|
|
for spn, d := range data.Definitions {
|
2019-09-26 23:06:08 -06:00
|
|
|
t.Run(spanName(spn), func(t *testing.T) {
|
|
|
|
t.Helper()
|
|
|
|
tests.Definition(t, spn, d)
|
|
|
|
})
|
2019-09-26 11:56:23 -06:00
|
|
|
}
|
2019-04-16 13:47:48 -06:00
|
|
|
})
|
|
|
|
|
2019-10-28 13:16:55 -06:00
|
|
|
t.Run("Implementation", func(t *testing.T) {
|
|
|
|
t.Helper()
|
|
|
|
for spn, m := range data.Implementationses {
|
|
|
|
t.Run(spanName(spn), func(t *testing.T) {
|
|
|
|
t.Helper()
|
|
|
|
tests.Implementation(t, spn, m)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2019-04-27 20:45:06 -06:00
|
|
|
t.Run("Highlight", func(t *testing.T) {
|
2019-04-16 13:47:48 -06:00
|
|
|
t.Helper()
|
2019-09-26 11:56:23 -06:00
|
|
|
for name, locations := range data.Highlights {
|
2019-09-26 23:06:08 -06:00
|
|
|
t.Run(name, func(t *testing.T) {
|
|
|
|
t.Helper()
|
|
|
|
tests.Highlight(t, name, locations)
|
|
|
|
})
|
2019-09-26 11:56:23 -06:00
|
|
|
}
|
2019-04-16 13:47:48 -06:00
|
|
|
})
|
|
|
|
|
2019-06-07 08:04:22 -06:00
|
|
|
t.Run("References", func(t *testing.T) {
|
|
|
|
t.Helper()
|
2019-09-26 11:56:23 -06:00
|
|
|
for src, itemList := range data.References {
|
2019-09-26 23:06:08 -06:00
|
|
|
t.Run(spanName(src), func(t *testing.T) {
|
|
|
|
t.Helper()
|
2019-10-19 15:26:56 -06:00
|
|
|
tests.References(t, src, itemList)
|
2019-09-26 23:06:08 -06:00
|
|
|
})
|
2019-09-26 11:56:23 -06:00
|
|
|
}
|
2019-06-07 08:04:22 -06:00
|
|
|
})
|
|
|
|
|
2019-06-18 08:23:37 -06:00
|
|
|
t.Run("Renames", func(t *testing.T) {
|
|
|
|
t.Helper()
|
2019-09-26 11:56:23 -06:00
|
|
|
for spn, newText := range data.Renames {
|
2019-09-26 23:06:08 -06:00
|
|
|
t.Run(uriName(spn.URI())+"_"+newText, func(t *testing.T) {
|
|
|
|
t.Helper()
|
|
|
|
tests.Rename(t, spn, newText)
|
|
|
|
})
|
2019-09-26 11:56:23 -06:00
|
|
|
}
|
2019-06-18 08:23:37 -06:00
|
|
|
})
|
|
|
|
|
2019-08-22 11:31:03 -06:00
|
|
|
t.Run("PrepareRenames", func(t *testing.T) {
|
|
|
|
t.Helper()
|
2019-09-26 11:56:23 -06:00
|
|
|
for src, want := range data.PrepareRenames {
|
2019-09-26 23:06:08 -06:00
|
|
|
t.Run(spanName(src), func(t *testing.T) {
|
|
|
|
t.Helper()
|
|
|
|
tests.PrepareRename(t, src, want)
|
|
|
|
})
|
2019-09-26 11:56:23 -06:00
|
|
|
}
|
2019-08-22 11:31:03 -06:00
|
|
|
})
|
|
|
|
|
2019-04-16 13:47:48 -06:00
|
|
|
t.Run("Symbols", func(t *testing.T) {
|
|
|
|
t.Helper()
|
2019-09-26 11:56:23 -06:00
|
|
|
for uri, expectedSymbols := range data.Symbols {
|
2019-09-26 23:06:08 -06:00
|
|
|
t.Run(uriName(uri), func(t *testing.T) {
|
|
|
|
t.Helper()
|
2019-10-27 11:41:48 -06:00
|
|
|
tests.Symbols(t, uri, expectedSymbols)
|
2019-09-26 23:06:08 -06:00
|
|
|
})
|
2019-09-26 11:56:23 -06:00
|
|
|
}
|
2019-04-16 13:47:48 -06:00
|
|
|
})
|
|
|
|
|
2019-05-14 19:20:41 -06:00
|
|
|
t.Run("SignatureHelp", func(t *testing.T) {
|
2019-04-16 13:47:48 -06:00
|
|
|
t.Helper()
|
2019-09-26 11:56:23 -06:00
|
|
|
for spn, expectedSignature := range data.Signatures {
|
2019-09-26 23:06:08 -06:00
|
|
|
t.Run(spanName(spn), func(t *testing.T) {
|
|
|
|
t.Helper()
|
|
|
|
tests.SignatureHelp(t, spn, expectedSignature)
|
|
|
|
})
|
2019-09-26 11:56:23 -06:00
|
|
|
}
|
2019-04-16 13:47:48 -06:00
|
|
|
})
|
2019-04-24 09:33:45 -06:00
|
|
|
|
2019-04-27 20:45:06 -06:00
|
|
|
t.Run("Link", func(t *testing.T) {
|
2019-04-24 09:33:45 -06:00
|
|
|
t.Helper()
|
2019-09-26 11:56:23 -06:00
|
|
|
for uri, wantLinks := range data.Links {
|
2019-09-26 23:06:08 -06:00
|
|
|
t.Run(uriName(uri), func(t *testing.T) {
|
|
|
|
t.Helper()
|
|
|
|
tests.Link(t, uri, wantLinks)
|
|
|
|
})
|
2019-09-26 11:56:23 -06:00
|
|
|
}
|
2019-04-24 09:33:45 -06:00
|
|
|
})
|
2019-05-01 17:16:03 -06:00
|
|
|
|
2019-09-23 21:12:28 -06:00
|
|
|
if *UpdateGolden {
|
2019-05-01 17:16:03 -06:00
|
|
|
for _, golden := range data.golden {
|
|
|
|
if !golden.Modified {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
sort.Slice(golden.Archive.Files, func(i, j int) bool {
|
|
|
|
return golden.Archive.Files[i].Name < golden.Archive.Files[j].Name
|
|
|
|
})
|
|
|
|
if err := ioutil.WriteFile(golden.Filename, txtar.Format(golden.Archive), 0666); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-04-16 13:47:48 -06:00
|
|
|
}
|
|
|
|
|
2019-09-26 10:54:25 -06:00
|
|
|
func checkData(t *testing.T, data *Data) {
|
|
|
|
buf := &bytes.Buffer{}
|
|
|
|
diagnosticsCount := 0
|
|
|
|
for _, want := range data.Diagnostics {
|
|
|
|
diagnosticsCount += len(want)
|
|
|
|
}
|
|
|
|
linksCount := 0
|
|
|
|
for _, want := range data.Links {
|
|
|
|
linksCount += len(want)
|
|
|
|
}
|
|
|
|
definitionCount := 0
|
|
|
|
typeDefinitionCount := 0
|
|
|
|
for _, d := range data.Definitions {
|
|
|
|
if d.IsType {
|
|
|
|
typeDefinitionCount++
|
|
|
|
} else {
|
|
|
|
definitionCount++
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fmt.Fprintf(buf, "CompletionsCount = %v\n", len(data.Completions))
|
|
|
|
fmt.Fprintf(buf, "CompletionSnippetCount = %v\n", len(data.CompletionSnippets))
|
|
|
|
fmt.Fprintf(buf, "UnimportedCompletionsCount = %v\n", len(data.UnimportedCompletions))
|
|
|
|
fmt.Fprintf(buf, "DeepCompletionsCount = %v\n", len(data.DeepCompletions))
|
|
|
|
fmt.Fprintf(buf, "FuzzyCompletionsCount = %v\n", len(data.FuzzyCompletions))
|
|
|
|
fmt.Fprintf(buf, "RankedCompletionsCount = %v\n", len(data.RankCompletions))
|
|
|
|
fmt.Fprintf(buf, "CaseSensitiveCompletionsCount = %v\n", len(data.CaseSensitiveCompletions))
|
|
|
|
fmt.Fprintf(buf, "DiagnosticsCount = %v\n", diagnosticsCount)
|
|
|
|
fmt.Fprintf(buf, "FoldingRangesCount = %v\n", len(data.FoldingRanges))
|
|
|
|
fmt.Fprintf(buf, "FormatCount = %v\n", len(data.Formats))
|
|
|
|
fmt.Fprintf(buf, "ImportCount = %v\n", len(data.Imports))
|
|
|
|
fmt.Fprintf(buf, "SuggestedFixCount = %v\n", len(data.SuggestedFixes))
|
|
|
|
fmt.Fprintf(buf, "DefinitionsCount = %v\n", definitionCount)
|
|
|
|
fmt.Fprintf(buf, "TypeDefinitionsCount = %v\n", typeDefinitionCount)
|
|
|
|
fmt.Fprintf(buf, "HighlightsCount = %v\n", len(data.Highlights))
|
|
|
|
fmt.Fprintf(buf, "ReferencesCount = %v\n", len(data.References))
|
|
|
|
fmt.Fprintf(buf, "RenamesCount = %v\n", len(data.Renames))
|
|
|
|
fmt.Fprintf(buf, "PrepareRenamesCount = %v\n", len(data.PrepareRenames))
|
|
|
|
fmt.Fprintf(buf, "SymbolsCount = %v\n", len(data.Symbols))
|
|
|
|
fmt.Fprintf(buf, "SignaturesCount = %v\n", len(data.Signatures))
|
|
|
|
fmt.Fprintf(buf, "LinksCount = %v\n", linksCount)
|
|
|
|
|
|
|
|
want := string(data.Golden("summary", "summary.txt", func() ([]byte, error) {
|
|
|
|
return buf.Bytes(), nil
|
|
|
|
}))
|
|
|
|
got := buf.String()
|
|
|
|
if want != got {
|
|
|
|
t.Errorf("test summary does not match, want\n%s\ngot:\n%s", want, got)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-09 22:36:39 -06:00
|
|
|
func (data *Data) Mapper(uri span.URI) (*protocol.ColumnMapper, error) {
|
|
|
|
data.mappersMu.Lock()
|
|
|
|
defer data.mappersMu.Unlock()
|
|
|
|
|
|
|
|
if _, ok := data.mappers[uri]; !ok {
|
|
|
|
content, err := data.Exported.FileContents(uri.Filename())
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
converter := span.NewContentConverter(uri.Filename(), content)
|
|
|
|
data.mappers[uri] = &protocol.ColumnMapper{
|
|
|
|
URI: uri,
|
|
|
|
Converter: converter,
|
|
|
|
Content: content,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return data.mappers[uri], nil
|
|
|
|
}
|
|
|
|
|
2019-05-01 17:16:03 -06:00
|
|
|
func (data *Data) Golden(tag string, target string, update func() ([]byte, error)) []byte {
|
2019-04-09 20:23:02 -06:00
|
|
|
data.t.Helper()
|
|
|
|
fragment, found := data.fragments[target]
|
|
|
|
if !found {
|
|
|
|
if filepath.IsAbs(target) {
|
|
|
|
data.t.Fatalf("invalid golden file fragment %v", target)
|
|
|
|
}
|
|
|
|
fragment = target
|
|
|
|
}
|
2019-05-01 17:16:03 -06:00
|
|
|
golden := data.golden[fragment]
|
|
|
|
if golden == nil {
|
2019-09-23 21:12:28 -06:00
|
|
|
if !*UpdateGolden {
|
2019-05-01 17:16:03 -06:00
|
|
|
data.t.Fatalf("could not find golden file %v: %v", fragment, tag)
|
|
|
|
}
|
|
|
|
golden = &Golden{
|
|
|
|
Filename: filepath.Join(data.dir, fragment+goldenFileSuffix),
|
|
|
|
Archive: &txtar.Archive{},
|
|
|
|
Modified: true,
|
|
|
|
}
|
|
|
|
data.golden[fragment] = golden
|
|
|
|
}
|
|
|
|
var file *txtar.File
|
|
|
|
for i := range golden.Archive.Files {
|
|
|
|
f := &golden.Archive.Files[i]
|
|
|
|
if f.Name == tag {
|
|
|
|
file = f
|
|
|
|
break
|
|
|
|
}
|
2019-04-09 20:23:02 -06:00
|
|
|
}
|
2019-09-23 21:12:28 -06:00
|
|
|
if *UpdateGolden {
|
2019-05-01 17:16:03 -06:00
|
|
|
if file == nil {
|
|
|
|
golden.Archive.Files = append(golden.Archive.Files, txtar.File{
|
|
|
|
Name: tag,
|
|
|
|
})
|
|
|
|
file = &golden.Archive.Files[len(golden.Archive.Files)-1]
|
|
|
|
}
|
|
|
|
contents, err := update()
|
|
|
|
if err != nil {
|
|
|
|
data.t.Fatalf("could not update golden file %v: %v", fragment, err)
|
2019-04-09 20:23:02 -06:00
|
|
|
}
|
2019-05-01 17:16:03 -06:00
|
|
|
file.Data = append(contents, '\n') // add trailing \n for txtar
|
|
|
|
golden.Modified = true
|
2019-04-09 20:23:02 -06:00
|
|
|
}
|
2019-05-01 17:16:03 -06:00
|
|
|
if file == nil {
|
|
|
|
data.t.Fatalf("could not find golden contents %v: %v", fragment, tag)
|
2019-04-09 20:23:02 -06:00
|
|
|
}
|
2019-05-01 17:16:03 -06:00
|
|
|
return file.Data[:len(file.Data)-1] // drop the trailing \n
|
2019-04-09 20:23:02 -06:00
|
|
|
}
|
|
|
|
|
2019-04-16 13:47:48 -06:00
|
|
|
func (data *Data) collectDiagnostics(spn span.Span, msgSource, msg string) {
|
|
|
|
if _, ok := data.Diagnostics[spn.URI()]; !ok {
|
|
|
|
data.Diagnostics[spn.URI()] = []source.Diagnostic{}
|
|
|
|
}
|
2019-09-24 22:46:57 -06:00
|
|
|
severity := protocol.SeverityError
|
2019-04-16 13:47:48 -06:00
|
|
|
if strings.Contains(string(spn.URI()), "analyzer") {
|
2019-09-24 22:46:57 -06:00
|
|
|
severity = protocol.SeverityWarning
|
2019-04-16 13:47:48 -06:00
|
|
|
}
|
2019-08-14 18:12:18 -06:00
|
|
|
// This is not the correct way to do this,
|
|
|
|
// but it seems excessive to do the full conversion here.
|
2019-04-16 13:47:48 -06:00
|
|
|
want := source.Diagnostic{
|
2019-08-14 18:12:18 -06:00
|
|
|
URI: spn.URI(),
|
|
|
|
Range: protocol.Range{
|
|
|
|
Start: protocol.Position{
|
|
|
|
Line: float64(spn.Start().Line()) - 1,
|
|
|
|
Character: float64(spn.Start().Column()) - 1,
|
|
|
|
},
|
|
|
|
End: protocol.Position{
|
|
|
|
Line: float64(spn.End().Line()) - 1,
|
|
|
|
Character: float64(spn.End().Column()) - 1,
|
|
|
|
},
|
|
|
|
},
|
2019-04-16 13:47:48 -06:00
|
|
|
Severity: severity,
|
|
|
|
Source: msgSource,
|
|
|
|
Message: msg,
|
|
|
|
}
|
|
|
|
data.Diagnostics[spn.URI()] = append(data.Diagnostics[spn.URI()], want)
|
|
|
|
}
|
|
|
|
|
2019-09-17 09:10:48 -06:00
|
|
|
func (data *Data) collectCompletions(typ CompletionTestType) func(span.Span, []token.Pos) {
|
|
|
|
result := func(m map[span.Span]Completion, src span.Span, expected []token.Pos) {
|
|
|
|
m[src] = Completion{
|
|
|
|
CompletionItems: expected,
|
|
|
|
}
|
2019-08-14 18:12:18 -06:00
|
|
|
}
|
2019-09-17 09:10:48 -06:00
|
|
|
switch typ {
|
|
|
|
case CompletionDeep:
|
|
|
|
return func(src span.Span, expected []token.Pos) {
|
|
|
|
result(data.DeepCompletions, src, expected)
|
2019-08-14 18:12:18 -06:00
|
|
|
}
|
2019-09-17 09:10:48 -06:00
|
|
|
case CompletionUnimported:
|
|
|
|
return func(src span.Span, expected []token.Pos) {
|
|
|
|
result(data.UnimportedCompletions, src, expected)
|
2019-08-14 18:12:18 -06:00
|
|
|
}
|
2019-09-17 09:10:48 -06:00
|
|
|
case CompletionFuzzy:
|
|
|
|
return func(src span.Span, expected []token.Pos) {
|
|
|
|
result(data.FuzzyCompletions, src, expected)
|
2019-08-14 18:12:18 -06:00
|
|
|
}
|
2019-09-17 09:10:48 -06:00
|
|
|
case CompletionRank:
|
|
|
|
return func(src span.Span, expected []token.Pos) {
|
|
|
|
result(data.RankCompletions, src, expected)
|
|
|
|
}
|
2019-09-26 05:59:06 -06:00
|
|
|
case CompletionCaseSensitve:
|
|
|
|
return func(src span.Span, expected []token.Pos) {
|
|
|
|
result(data.CaseSensitiveCompletions, src, expected)
|
|
|
|
}
|
2019-09-17 09:10:48 -06:00
|
|
|
default:
|
|
|
|
return func(src span.Span, expected []token.Pos) {
|
|
|
|
result(data.Completions, src, expected)
|
2019-06-17 21:56:06 -06:00
|
|
|
}
|
|
|
|
}
|
2019-04-16 13:47:48 -06:00
|
|
|
}
|
|
|
|
|
2019-08-06 16:51:17 -06:00
|
|
|
func (data *Data) collectCompletionItems(pos token.Pos, args []string) {
|
|
|
|
if len(args) < 3 {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
label, detail, kind := args[0], args[1], args[2]
|
|
|
|
var documentation string
|
|
|
|
if len(args) == 4 {
|
|
|
|
documentation = args[3]
|
|
|
|
}
|
2019-04-16 13:47:48 -06:00
|
|
|
data.CompletionItems[pos] = &source.CompletionItem{
|
2019-08-06 16:51:17 -06:00
|
|
|
Label: label,
|
|
|
|
Detail: detail,
|
2019-09-24 22:46:57 -06:00
|
|
|
Kind: protocol.ParseCompletionItemKind(kind),
|
2019-08-06 16:51:17 -06:00
|
|
|
Documentation: documentation,
|
2019-04-16 13:47:48 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-28 19:48:29 -06:00
|
|
|
func (data *Data) collectFoldingRanges(spn span.Span) {
|
|
|
|
data.FoldingRanges = append(data.FoldingRanges, spn)
|
|
|
|
}
|
|
|
|
|
2019-04-22 16:15:39 -06:00
|
|
|
func (data *Data) collectFormats(spn span.Span) {
|
|
|
|
data.Formats = append(data.Formats, spn)
|
2019-04-16 13:47:48 -06:00
|
|
|
}
|
|
|
|
|
2019-05-31 20:42:59 -06:00
|
|
|
func (data *Data) collectImports(spn span.Span) {
|
|
|
|
data.Imports = append(data.Imports, spn)
|
|
|
|
}
|
|
|
|
|
2019-09-04 11:16:09 -06:00
|
|
|
func (data *Data) collectSuggestedFixes(spn span.Span) {
|
|
|
|
data.SuggestedFixes = append(data.SuggestedFixes, spn)
|
|
|
|
}
|
|
|
|
|
2019-04-16 13:47:48 -06:00
|
|
|
func (data *Data) collectDefinitions(src, target span.Span) {
|
|
|
|
data.Definitions[src] = Definition{
|
|
|
|
Src: src,
|
|
|
|
Def: target,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-28 13:16:55 -06:00
|
|
|
func (data *Data) collectImplementations(src, target span.Span) {
|
|
|
|
// Add target to the list of expected implementations for src
|
|
|
|
imps := data.Implementationses[src]
|
|
|
|
imps.Src = src // Src is already set if imps already exists, but then we're setting it to the same thing.
|
|
|
|
imps.Implementations = append(imps.Implementations, target)
|
|
|
|
data.Implementationses[src] = imps
|
|
|
|
}
|
|
|
|
|
2019-05-15 15:58:16 -06:00
|
|
|
func (data *Data) collectHoverDefinitions(src, target span.Span) {
|
|
|
|
data.Definitions[src] = Definition{
|
|
|
|
Src: src,
|
|
|
|
Def: target,
|
|
|
|
OnlyHover: true,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-16 13:47:48 -06:00
|
|
|
func (data *Data) collectTypeDefinitions(src, target span.Span) {
|
|
|
|
data.Definitions[src] = Definition{
|
|
|
|
Src: src,
|
|
|
|
Def: target,
|
|
|
|
IsType: true,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-01 17:16:03 -06:00
|
|
|
func (data *Data) collectDefinitionNames(src span.Span, name string) {
|
|
|
|
d := data.Definitions[src]
|
|
|
|
d.Name = name
|
|
|
|
data.Definitions[src] = d
|
|
|
|
}
|
|
|
|
|
2019-04-16 13:47:48 -06:00
|
|
|
func (data *Data) collectHighlights(name string, rng span.Span) {
|
|
|
|
data.Highlights[name] = append(data.Highlights[name], rng)
|
|
|
|
}
|
|
|
|
|
2019-06-07 08:04:22 -06:00
|
|
|
func (data *Data) collectReferences(src span.Span, expected []span.Span) {
|
|
|
|
data.References[src] = expected
|
|
|
|
}
|
|
|
|
|
2019-06-18 08:23:37 -06:00
|
|
|
func (data *Data) collectRenames(src span.Span, newText string) {
|
|
|
|
data.Renames[src] = newText
|
|
|
|
}
|
|
|
|
|
2019-08-22 11:31:03 -06:00
|
|
|
func (data *Data) collectPrepareRenames(src span.Span, rng span.Range, placeholder string) {
|
|
|
|
if int(rng.End-rng.Start) != len(placeholder) {
|
|
|
|
// If the length of the placeholder and the length of the range do not match,
|
|
|
|
// make the range just be the start.
|
|
|
|
rng = span.NewRange(rng.FileSet, rng.Start, rng.Start)
|
|
|
|
}
|
2019-09-09 22:36:39 -06:00
|
|
|
m, err := data.Mapper(src.URI())
|
2019-09-05 18:04:28 -06:00
|
|
|
if err != nil {
|
2019-09-09 22:36:39 -06:00
|
|
|
data.t.Fatal(err)
|
2019-09-05 18:04:28 -06:00
|
|
|
}
|
|
|
|
// Convert range to span and then to protocol.Range.
|
|
|
|
spn, err := rng.Span()
|
|
|
|
if err != nil {
|
2019-09-09 22:36:39 -06:00
|
|
|
data.t.Fatal(err)
|
2019-09-05 18:04:28 -06:00
|
|
|
}
|
|
|
|
prng, err := m.Range(spn)
|
|
|
|
if err != nil {
|
2019-09-09 22:36:39 -06:00
|
|
|
data.t.Fatal(err)
|
2019-09-05 18:04:28 -06:00
|
|
|
}
|
2019-08-22 11:31:03 -06:00
|
|
|
data.PrepareRenames[src] = &source.PrepareItem{
|
2019-09-05 18:04:28 -06:00
|
|
|
Range: prng,
|
2019-08-22 11:31:03 -06:00
|
|
|
Text: placeholder,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-16 13:47:48 -06:00
|
|
|
func (data *Data) collectSymbols(name string, spn span.Span, kind string, parentName string) {
|
2019-09-09 22:36:39 -06:00
|
|
|
m, err := data.Mapper(spn.URI())
|
2019-09-05 16:54:05 -06:00
|
|
|
if err != nil {
|
2019-09-09 22:36:39 -06:00
|
|
|
data.t.Fatal(err)
|
2019-09-05 16:54:05 -06:00
|
|
|
}
|
|
|
|
rng, err := m.Range(spn)
|
|
|
|
if err != nil {
|
2019-09-09 22:36:39 -06:00
|
|
|
data.t.Fatal(err)
|
2019-09-05 16:54:05 -06:00
|
|
|
}
|
|
|
|
sym := protocol.DocumentSymbol{
|
|
|
|
Name: name,
|
|
|
|
Kind: protocol.ParseSymbolKind(kind),
|
|
|
|
SelectionRange: rng,
|
2019-04-16 13:47:48 -06:00
|
|
|
}
|
|
|
|
if parentName == "" {
|
|
|
|
data.Symbols[spn.URI()] = append(data.Symbols[spn.URI()], sym)
|
|
|
|
} else {
|
|
|
|
data.symbolsChildren[parentName] = append(data.symbolsChildren[parentName], sym)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (data *Data) collectSignatures(spn span.Span, signature string, activeParam int64) {
|
2019-06-28 19:27:41 -06:00
|
|
|
data.Signatures[spn] = &source.SignatureInformation{
|
2019-04-16 13:47:48 -06:00
|
|
|
Label: signature,
|
|
|
|
ActiveParameter: int(activeParam),
|
|
|
|
}
|
2019-06-28 19:27:41 -06:00
|
|
|
// Hardcode special case to test the lack of a signature.
|
|
|
|
if signature == "" && activeParam == 0 {
|
|
|
|
data.Signatures[spn] = nil
|
|
|
|
}
|
2019-04-16 13:47:48 -06:00
|
|
|
}
|
2019-04-28 21:19:54 -06:00
|
|
|
|
|
|
|
func (data *Data) collectCompletionSnippets(spn span.Span, item token.Pos, plain, placeholder string) {
|
|
|
|
data.CompletionSnippets[spn] = CompletionSnippet{
|
|
|
|
CompletionItem: item,
|
|
|
|
PlainSnippet: plain,
|
|
|
|
PlaceholderSnippet: placeholder,
|
|
|
|
}
|
|
|
|
}
|
2019-04-24 09:33:45 -06:00
|
|
|
|
2019-07-07 16:25:19 -06:00
|
|
|
func (data *Data) collectLinks(spn span.Span, link string, note *expect.Note, fset *token.FileSet) {
|
|
|
|
position := fset.Position(note.Pos)
|
2019-04-24 09:33:45 -06:00
|
|
|
uri := spn.URI()
|
|
|
|
data.Links[uri] = append(data.Links[uri], Link{
|
2019-07-07 16:25:19 -06:00
|
|
|
Src: spn,
|
|
|
|
Target: link,
|
|
|
|
NotePosition: position,
|
2019-04-24 09:33:45 -06:00
|
|
|
})
|
|
|
|
}
|
2019-09-26 23:06:08 -06:00
|
|
|
|
|
|
|
func uriName(uri span.URI) string {
|
|
|
|
return filepath.Base(strings.TrimSuffix(uri.Filename(), ".go"))
|
|
|
|
}
|
|
|
|
|
|
|
|
func spanName(spn span.Span) string {
|
|
|
|
return fmt.Sprintf("%v_%v_%v", uriName(spn.URI()), spn.Start().Line(), spn.Start().Column())
|
|
|
|
}
|