Move LSP semantics into typed analysis
This commit is contained in:
parent
f4cd4f4458
commit
bac1183593
26 changed files with 1232 additions and 637 deletions
37
internal/lang/diagnostics_test.go
Normal file
37
internal/lang/diagnostics_test.go
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
package lang
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestAnalyzeProducesStructuredUndefinedDiagnostic(t *testing.T) {
|
||||
source := `package demo fun main() { println(missing) }`
|
||||
program, err := Parse(source)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
_, diagnostics := AnalyzeWithContext(program, nil)
|
||||
if len(diagnostics) != 1 {
|
||||
t.Fatalf("diagnostics = %#v", diagnostics)
|
||||
}
|
||||
diagnostic := diagnostics[0]
|
||||
if diagnostic.Code != "undefined-symbol" || diagnostic.Severity != DiagnosticError || diagnostic.Message != "undefined identifier missing" {
|
||||
t.Fatalf("unexpected diagnostic: %#v", diagnostic)
|
||||
}
|
||||
if got := source[diagnostic.Span.Start:diagnostic.Span.End]; got != "missing" {
|
||||
t.Fatalf("diagnostic span = %q", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestAnalyzeUsesAdditionalPackagePrograms(t *testing.T) {
|
||||
current, err := Parse(`package demo fun main() { helper() }`)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
sibling, err := Parse(`package demo fun helper() { println("ok") }`)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
_, diagnostics := AnalyzeWithContext(current, []*Program{sibling})
|
||||
if len(diagnostics) != 0 {
|
||||
t.Fatalf("package symbol was not resolved: %#v", diagnostics)
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue