Move LSP semantics into typed analysis

This commit is contained in:
pavel 2026-08-27 21:28:11 +02:00
commit bac1183593
26 changed files with 1232 additions and 637 deletions

View 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)
}
}