package app import ( "path/filepath" "testing" "codeberg.org/turbo-editors/turbo-core/lsp" ) func TestDiagnosticsAreFoundForAFileOpenedByARelativePath(t *testing.T) { // Found by driving the real editor against a real gopls: the Problems // window listed two errors and the gutter showed none, because the two // sides spell the file differently. A server publishes absolute URIs; a // buffer opened as "turbo-go main.go" holds the relative path it was // given. The status bar had been failing the same way since long before // the marks existed, silently, because an editor with no error to show and // an editor that cannot find the error look identical. project := t.TempDir() t.Chdir(project) t.Setenv(testProfile().SnippetDirEnvVar(), t.TempDir()) a, _ := newTestApp(t) writeTestFile(t, filepath.Join(project, "main.go"), "package main\n\nfunc main() { x }\n") a.Open("main.go") // relative, as the command line gives it a.language.receiveDiagnostics(filepath.Join(project, "main.go"), []lsp.Diagnostic{ {Message: "undefined: x", Severity: lsp.SeverityError, Range: lsp.Range{Start: lsp.Position{Line: 2}}}, }) a.Tick() if _, found := a.language.FirstError(a.ActiveView().Buffer().Path()); !found { t.Errorf("no error found for %q, though one was published for the same file", a.ActiveView().Buffer().Path()) } if got := a.ActiveView().Marks()[2]; got == 0 { t.Errorf("line 3 is unmarked, though an error was published for it") } } func TestDiagnosticsAreFoundWhicheverWaySpelt(t *testing.T) { // Both directions, since either side may be the relative one. project := t.TempDir() t.Chdir(project) a, _ := newTestApp(t) a.language.receiveDiagnostics("main.go", []lsp.Diagnostic{{Message: "relative in"}}) if got := a.language.Diagnostics(filepath.Join(project, "main.go")); len(got) != 1 { t.Errorf("published relative, read absolute: got %d diagnostics", len(got)) } a.language.receiveDiagnostics(filepath.Join(project, "other.go"), []lsp.Diagnostic{{Message: "absolute in"}}) if got := a.language.Diagnostics("other.go"); len(got) != 1 { t.Errorf("published absolute, read relative: got %d diagnostics", len(got)) } } func TestKnowsDoesNotDependOnTheSpellingOfThePath(t *testing.T) { // The map of open documents is keyed the same way as the diagnostics: // absolute. Keyed by whatever string DidOpen was given, a file opened as // "main.go" would not be known as "/project/main.go" — and saving, which // asks Knows to decide between announcing a document and reporting a // write, would announce the same document twice. project := t.TempDir() t.Chdir(project) a, _ := newTestApp(t) client, _ := newFakeLanguage(t, a) connectLanguage(a, client) a.language.DidOpen("main.go", "package main\n") absolute := filepath.Join(project, "main.go") if !a.language.Knows(absolute) { t.Errorf("opened as %q, not known as %q", "main.go", absolute) } if !a.language.Knows("main.go") { t.Errorf("opened as %q, not known under that very spelling", "main.go") } a.language.DidClose(absolute) if a.language.Knows("main.go") { t.Errorf("closed as %q, still known as %q", absolute, "main.go") } }