turbo-editors/turbo-corepublic Fork 0
v1.0.0
Commits
Clone
git clone https://git.rickub.com/turbo-editors/turbo-core.git
git clone ssh://git@rickub.com/turbo-editors/turbo-core.git

Host key fingerprint (ed25519): SHA256:iycHnxEyq0Q7uyVpB7JlznP0G7JrTPXLYRcAU5CSLhc — verify it before your first connect.

📦 Turbo Core f3ade8d · on v1.0.0 · k33g · 9h ago
diagnostics_test.go · 83 lines · 3.1 KBGo Blame HistoryRaw
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
package app

import (
	"path/filepath"
	"testing"

	"rickub.com/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")
	}
}