Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions internal/semantic/lsp/enrich_confirm.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,13 +125,14 @@ func (p *Provider) groupConfirmTargets(nodesByID map[string]*graph.Node, targets
// containment in the caller's span. Pure over its inputs, so it is safe to call
// from the parallel sweep.
func (p *Provider) confirmRefMatchesSite(refs []Location, absRoot, repoPrefix string, t enrichTarget) bool {
callerRel := nodeRelPath(t.node)
siteRel := edgeSiteRelPath(t.edge, repoPrefix, callerRel)
callerRel := viewPathKey(nodeRelPath(t.node))
siteRel := viewPathKey(edgeSiteRelPath(t.edge, repoPrefix, callerRel))
siteLine := t.edge.Line
for _, ref := range refs {
// uriToPath returns a repo-relative path while node/edge FilePaths are
// prefixed, so compare against stripped paths.
refPath := uriToPath(ref.URI, absRoot)
// prefixed, so compare against stripped paths — slash-normalized, since
// store rows may spell separators either way.
refPath := viewPathKey(uriToPath(ref.URI, absRoot))
refLine := ref.Range.Start.Line + 1
if siteLine > 0 {
if refPath == siteRel && refLine >= siteLine-1 && refLine <= siteLine+1 {
Expand Down
43 changes: 37 additions & 6 deletions internal/semantic/lsp/graph_batch.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,36 @@
package lsp

import (
"strings"

"github.com/zzet/gortex/internal/graph"
"github.com/zzet/gortex/internal/semantic"
)

// viewPathKey normalizes a graph file path for nodesByFile keying and
// comparisons. Store vintages carry both separator spellings — older
// Windows rows use `\` after the repo prefix while newer rows and every
// URI-derived path use `/` — so any join between a server answer and a
// node path must use the slash-normalized spelling. Mirrors the store's
// own file_dir separator normalization.
func viewPathKey(p string) string { return strings.ReplaceAll(p, `\`, "/") }

// storePathSpellings returns the scoped-path spellings a store row may
// carry for a repo-relative path: the slash spelling plus, when the rel
// has separators, the backslash spelling older Windows rows use. Store
// lookups by file_path are exact string matches, so a URI-derived
// slash-relative path must query both.
func storePathSpellings(repoPrefix, rel string) []string {
if rel == "" {
return nil
}
spellings := []string{scopedPath(repoPrefix, rel)}
if back := strings.ReplaceAll(rel, "/", `\`); back != rel {
spellings = append(spellings, scopedPath(repoPrefix, back))
}
return spellings
}

type lspEdgeKey struct {
from string
to string
Expand Down Expand Up @@ -46,24 +72,26 @@ func (v *lspGraphView) addNodes(nodes []*graph.Node) {
}
if old, exists := v.nodesByID[n.ID]; exists {
v.nodesByID[n.ID] = n
bucket := v.nodesByFile[old.FilePath]
oldKey, newKey := viewPathKey(old.FilePath), viewPathKey(n.FilePath)
bucket := v.nodesByFile[oldKey]
for i, candidate := range bucket {
if candidate.ID != n.ID {
continue
}
if old.FilePath == n.FilePath {
if oldKey == newKey {
bucket[i] = n
v.nodesByFile[old.FilePath] = bucket
v.nodesByFile[oldKey] = bucket
} else {
v.nodesByFile[old.FilePath] = append(bucket[:i], bucket[i+1:]...)
v.nodesByFile[n.FilePath] = append(v.nodesByFile[n.FilePath], n)
v.nodesByFile[oldKey] = append(bucket[:i], bucket[i+1:]...)
v.nodesByFile[newKey] = append(v.nodesByFile[newKey], n)
}
break
}
continue
}
v.nodesByID[n.ID] = n
v.nodesByFile[n.FilePath] = append(v.nodesByFile[n.FilePath], n)
key := viewPathKey(n.FilePath)
v.nodesByFile[key] = append(v.nodesByFile[key], n)
}
}

Expand All @@ -83,6 +111,7 @@ func (v *lspGraphView) addEdges(edges []*graph.Edge) {
}

func (v *lspGraphView) matchNodeByFileLine(filePath string, line int) *graph.Node {
filePath = viewPathKey(filePath)
var best *graph.Node
bestSize := int(^uint(0) >> 1)
for _, n := range v.nodesByFile[filePath] {
Expand Down Expand Up @@ -118,6 +147,7 @@ func (v *lspGraphView) matchNodeByFileLine(filePath string, line int) *graph.Nod
}

func (v *lspGraphView) matchCallableByFileLine(filePath string, line int) *graph.Node {
filePath = viewPathKey(filePath)
callable := func(k graph.NodeKind) bool {
return k == graph.KindFunction || k == graph.KindMethod || k == graph.KindClosure
}
Expand Down Expand Up @@ -156,6 +186,7 @@ func (v *lspGraphView) matchCallableByFileLine(filePath string, line int) *graph
}

func (v *lspGraphView) findDeclarationNode(filePath string, oneBasedLine int, name string) *graph.Node {
filePath = viewPathKey(filePath)
var near *graph.Node
for _, n := range v.nodesByFile[filePath] {
if n == nil || n.Name != name {
Expand Down
13 changes: 8 additions & 5 deletions internal/semantic/lsp/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -2829,12 +2829,15 @@ func (p *Provider) ConfirmSymbolRefs(g graph.Store, repoRoot string, n *graph.No
if otherPath == "" {
continue
}
path := scopedPath(n.RepoPrefix, otherPath)
if _, seen := seenPath[path]; seen {
continue
// Store rows may spell separators either way, and the file_path
// lookup is an exact match — fetch every spelling a row may carry.
for _, path := range storePathSpellings(n.RepoPrefix, otherPath) {
if _, seen := seenPath[path]; seen {
continue
}
seenPath[path] = struct{}{}
paths = append(paths, path)
}
seenPath[path] = struct{}{}
paths = append(paths, path)
}
if len(paths) == 0 {
return 0, nil
Expand Down
68 changes: 68 additions & 0 deletions internal/semantic/lsp/windows_answer_join_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package lsp

import (
"path/filepath"
"testing"

"github.com/zzet/gortex/internal/graph"
)

// Graph FilePaths carry both separator spellings across store vintages —
// older Windows rows use `\` after the repo prefix while newer rows and
// every URI-derived path use `/` — so each join between a server answer
// and a graph node must match across spellings. Before these pins, every
// LSP answer on a backslash-spelled store missed its node: zero yield
// from a perfectly answering server, and the productivity checkpoint then
// cancelled the pass.

func TestGraphViewLookupsMatchAcrossSeparatorSpellings(t *testing.T) {
iface := &graph.Node{ID: "n1", Kind: graph.KindInterface, Name: "IThing",
FilePath: `repo/pkg\IThing.cs`, StartLine: 5, EndLine: 20}
method := &graph.Node{ID: "n2", Kind: graph.KindMethod, Name: "Handle",
FilePath: "repo/pkg2/Impl.cs", StartLine: 8, EndLine: 30}
view := newLSPGraphView([]*graph.Node{iface, method}, nil)

if got := view.matchNodeByFileLine("repo/pkg/IThing.cs", 10); got != iface {
t.Fatalf("slash lookup vs backslash-spelled node: got %+v, want iface", got)
}
if got := view.matchCallableByFileLine(`repo/pkg2\Impl.cs`, 12); got != method {
t.Fatalf("backslash lookup vs slash-spelled node: got %+v, want method", got)
}
if got := view.findDeclarationNode("repo/pkg/IThing.cs", 5, "IThing"); got != iface {
t.Fatalf("findDeclarationNode across spellings: got %+v, want iface", got)
}
}

func TestStorePathSpellingsCoverBothSeparators(t *testing.T) {
got := storePathSpellings("repo", "a/b/C.cs")
want := []string{"repo/a/b/C.cs", `repo/a\b\C.cs`}
if len(got) != len(want) || got[0] != want[0] || got[1] != want[1] {
t.Fatalf("spellings: got %q, want %q", got, want)
}
if got := storePathSpellings("repo", "C.cs"); len(got) != 1 || got[0] != "repo/C.cs" {
t.Fatalf("separator-free rel: got %q, want the single slash spelling", got)
}
if got := storePathSpellings("repo", ""); got != nil {
t.Fatalf("empty rel: got %q, want nil", got)
}
}

func TestConfirmRefMatchesSiteAcrossSeparatorSpellings(t *testing.T) {
absRoot := t.TempDir()
caller := &graph.Node{ID: "c1", Kind: graph.KindMethod, Name: "Caller",
RepoPrefix: "repo", FilePath: `repo/Domain\Svc.cs`, StartLine: 30, EndLine: 60}
edge := &graph.Edge{From: "c1", To: "t1", Kind: graph.EdgeCalls,
FilePath: `repo/Domain\Svc.cs`, Line: 42}
// The server answers with a URI, so the ref path comes back
// slash-spelled; the edge site is backslash-spelled.
ref := Location{
URI: pathToURI(filepath.Join(absRoot, "Domain", "Svc.cs")),
Range: Range{Start: Position{Line: 41}},
}

p := &Provider{}
if !p.confirmRefMatchesSite([]Location{ref}, absRoot, "repo",
enrichTarget{node: caller, edge: edge}) {
t.Fatal("reference at the site line must confirm across separator spellings")
}
}
Loading