hi
\n"), + }, + }, + { + name: "a longer tag name is not a script", + ext: ".vue", + parts: []part{ + markup("{label}
\n\n", + language: core.LanguageCodeJavascript, + imports: []importAt{{"left-pad", 3}}, + calls: []callAt{{"pad", 4, 15}}, + }, + } + dir := t.TempDir() + contents := map[string]string{} + for name, f := range files { + contents[name] = f.content + } + writeFiles(t, dir, contents) + fsys := appFileSystem(t, dir) + opts := Options{Languages: projectLanguages(t), Store: memstore.New()} + + cold, err := runIndexer(t, context.Background(), fsys, opts) + require.NoError(t, err) + assert.Empty(t, cold.Report.Failed) + require.Len(t, cold.Indexes, len(files)) + for _, ix := range cold.Indexes { + want := files[ix.Path] + t.Run(ix.Path, func(t *testing.T) { + assert.Equal(t, want.language, ix.Language) + assert.Equal(t, want.language, cold.Languages[ix.Path]) + assert.Equal(t, fileindex.FileIndexed, cold.Files[ix.Path]) + var imports []importAt + for _, imp := range ix.Imports { + imports = append(imports, importAt{imp.Module, imp.Line}) + } + assert.Equal(t, want.imports, imports) + var calls []callAt + for _, c := range ix.Calls { + calls = append(calls, callAt{c.Callee, c.Line, c.Column}) + } + assert.Equal(t, want.calls, calls) + }) + } + + warm, err := runIndexer(t, context.Background(), fsys, opts) + require.NoError(t, err) + assert.Empty(t, warm.Report.Visited) + assert.Equal(t, cold.Indexes, warm.Indexes) +} diff --git a/plugin/indexer/languages.go b/plugin/indexer/languages.go index 34e0dae0..3325e8e4 100644 --- a/plugin/indexer/languages.go +++ b/plugin/indexer/languages.go @@ -1,7 +1,10 @@ package indexer import ( + "context" + "github.com/safedep/code/core" + "github.com/safedep/code/core/ast" "github.com/safedep/code/fileindex" sitter "github.com/smacker/go-tree-sitter" ) @@ -29,6 +32,19 @@ type languageRules struct { // on such a receiver gets the key of the name in its scope as its // target, as main.py//run//t//do, so the link step reads the type. typedReceivers bool + // declaredAt reports whether the declared type of a name holds at a + // call: the caller binds the name once, as a parameter or a typed + // local, before the call. Rust reads it for w.write() after + // let w: Box