From d1987505d8e3d28ebb9c8284f2d3c4a832ea9cbc Mon Sep 17 00:00:00 2001 From: Jackie Li Date: Mon, 15 Jul 2024 17:53:21 +0100 Subject: [PATCH 1/7] add primitive document symbol support --- cmd/templ/lspcmd/lsp_test.go | 143 +++++++++++++++++++++++++++++++ cmd/templ/lspcmd/proxy/server.go | 84 +++++++++++++++++- 2 files changed, 224 insertions(+), 3 deletions(-) diff --git a/cmd/templ/lspcmd/lsp_test.go b/cmd/templ/lspcmd/lsp_test.go index 6e9f914f1..365d222da 100644 --- a/cmd/templ/lspcmd/lsp_test.go +++ b/cmd/templ/lspcmd/lsp_test.go @@ -2,6 +2,7 @@ package lspcmd import ( "context" + "encoding/json" "fmt" "io" "os" @@ -14,6 +15,7 @@ import ( "github.com/a-h/templ/cmd/templ/generatecmd/modcheck" "github.com/a-h/templ/cmd/templ/lspcmd/lspdiff" "github.com/a-h/templ/cmd/templ/testproject" + "github.com/google/go-cmp/cmp" "go.lsp.dev/jsonrpc2" "go.lsp.dev/uri" "go.uber.org/zap" @@ -442,6 +444,147 @@ func TestCodeAction(t *testing.T) { } } +func TestDocumentSymbol(t *testing.T) { + if testing.Short() { + return + } + + ctx, cancel := context.WithCancel(context.Background()) + log := zap.NewNop() + // log, err := zap.NewDevelopment() + // if err != nil { + // t.Fatalf("failed to create logger: %v", err) + // } + + ctx, appDir, _, server, teardown, err := Setup(ctx, log) + if err != nil { + t.Fatalf("failed to setup test: %v", err) + } + defer teardown(t) + defer cancel() + + templFile, err := os.ReadFile(appDir + "/templates.templ") + if err != nil { + t.Fatalf("failed to read file %q: %v", appDir+"/templates.templ", err) + } + err = server.DidOpen(ctx, &protocol.DidOpenTextDocumentParams{ + TextDocument: protocol.TextDocumentItem{ + URI: uri.URI("file://" + appDir + "/templates.templ"), + LanguageID: "templ", + Version: 1, + Text: string(templFile), + }, + }) + if err != nil { + t.Errorf("failed to register open file: %v", err) + return + } + log.Info("Calling hover") + + // Edit the file. + // Replace: + //
{ fmt.Sprintf("%d", count) }
+ // With various tests: + //
{ f + tests := []struct { + line int + replacement string + cursor string + expect []any + }{ + { + line: 13, + replacement: `
{ fmt.Sprintf("%d", count) }
`, + cursor: ` ^`, + expect: []any{ + protocol.SymbolInformation{ + Name: "nihao", + Kind: protocol.SymbolKindVariable, + Location: protocol.Location{ + URI: uri.URI("file://" + appDir + "/templates.templ"), + Range: protocol.Range{ + Start: protocol.Position{ + Line: 18, + Character: 4, + }, + End: protocol.Position{ + Line: 18, + Character: 16, + }, + }, + }, + }, + protocol.SymbolInformation{ + Name: "Page(count int)", + Kind: protocol.SymbolKindFunction, + Location: protocol.Location{ + URI: uri.URI("file://" + appDir + "/templates.templ"), + Range: protocol.Range{ + Start: protocol.Position{ + Line: 4, + Character: 6, + }, + End: protocol.Position{ + Line: 4, + Character: 21, + }, + }, + }, + }, + }, + }, + } + + for i, test := range tests { + t.Run(fmt.Sprintf("test-%d", i), func(t *testing.T) { + // Put the file back to the initial point. + err = server.DidChange(ctx, &protocol.DidChangeTextDocumentParams{ + TextDocument: protocol.VersionedTextDocumentIdentifier{ + TextDocumentIdentifier: protocol.TextDocumentIdentifier{ + URI: uri.URI("file://" + appDir + "/templates.templ"), + }, + Version: int32(i + 2), + }, + ContentChanges: []protocol.TextDocumentContentChangeEvent{ + { + Range: nil, + Text: string(templFile), + }, + }, + }) + if err != nil { + t.Errorf("failed to change file: %v", err) + return + } + + // Give CI/CD pipeline executors some time because they're often quite slow. + actual, err := server.DocumentSymbol(ctx, &protocol.DocumentSymbolParams{ + TextDocument: protocol.TextDocumentIdentifier{ + URI: uri.URI("file://" + appDir + "/templates.templ"), + }, + }) + if err != nil { + t.Errorf("failed to get document symbol: %v", err) + } + expectdSlice, err := sliceToAnySlice(test.expect) + if err != nil { + t.Errorf("failed to convert expect to any slice: %v", err) + } + diff := cmp.Diff(expectdSlice, actual) + if diff != "" { + t.Errorf("unexpected document symbol: %v", diff) + } + }) + } +} + +func sliceToAnySlice(in []any) ([]any, error) { + b, err := json.Marshal(in) + out := make([]any, 0, len(in)) + err = json.Unmarshal(b, &out) + return out, err +} + func runeIndexToUTF8ByteIndex(s string, runeIndex int) (lspChar uint32, err error) { for i, r := range []rune(s) { if i == runeIndex { diff --git a/cmd/templ/lspcmd/proxy/server.go b/cmd/templ/lspcmd/proxy/server.go index 8ac3597b2..854c13e1f 100644 --- a/cmd/templ/lspcmd/proxy/server.go +++ b/cmd/templ/lspcmd/proxy/server.go @@ -2,6 +2,7 @@ package proxy import ( "context" + "encoding/json" "fmt" "regexp" "strings" @@ -753,9 +754,52 @@ func (p *Server) DocumentLinkResolve(ctx context.Context, params *lsp.DocumentLi func (p *Server) DocumentSymbol(ctx context.Context, params *lsp.DocumentSymbolParams) (result []interface{} /* []SymbolInformation | []DocumentSymbol */, err error) { p.Log.Info("client -> server: DocumentSymbol") defer p.Log.Info("client -> server: DocumentSymbol end") - // TODO: Rewrite the request and response, but for now, ignore it. - // return p.Target.DocumentSymbol(ctx params) - return + symbols, err := p.Target.DocumentSymbol(ctx, params) + if err != nil { + return nil, err + } + requireDocumentSymbols := false + for _, s := range symbols { + if m, ok := s.(map[string]interface{}); ok { + s, err = mapToSymbol(m) + if err != nil { + return nil, err + } + } + switch s.(type) { + case lsp.DocumentSymbol: + requireDocumentSymbols = true + case lsp.SymbolInformation: + } + result = append(result, s) + } + + // TODO: it looks like we only have SymbolInformation in the result. We should handle DocumentSymbol as well. + _ = requireDocumentSymbols + + doc, ok := p.TemplSource.Get(string(params.TextDocument.URI)) + if ok { + template, err := parser.ParseString(doc.String()) + if err == nil { + for _, s := range template.Nodes { + switch s := s.(type) { + case parser.TemplateFileGoExpression: + case parser.HTMLTemplate: + result = append(result, lsp.SymbolInformation{ + Name: s.Expression.Value, + Kind: lsp.SymbolKindFunction, + Location: lsp.Location{ + URI: params.TextDocument.URI, + Range: parserRangeToLspRange(s.Expression.Range), + }, + }) + case parser.CSSTemplate: + case parser.ScriptTemplate: + } + } + } + } + return result, err } func (p *Server) ExecuteCommand(ctx context.Context, params *lsp.ExecuteCommandParams) (result interface{}, err error) { @@ -1141,3 +1185,37 @@ func (p *Server) Request(ctx context.Context, method string, params interface{}) defer p.Log.Info("client -> server: Request end") return p.Target.Request(ctx, method, params) } + +func mapToSymbol(m map[string]interface{}) (interface{}, error) { + b, err := json.Marshal(m) + if err != nil { + return nil, err + } + + if _, ok := m["selectionRange"]; ok { + var s lsp.DocumentSymbol + if err := json.Unmarshal(b, &s); err != nil { + return nil, err + } + return s, nil + } + + var s lsp.SymbolInformation + if err := json.Unmarshal(b, &s); err != nil { + return nil, err + } + return s, nil +} + +func parserRangeToLspRange(r parser.Range) lsp.Range { + return lsp.Range{ + Start: lsp.Position{ + Line: r.From.Line, + Character: r.From.Col, + }, + End: lsp.Position{ + Line: r.To.Line, + Character: r.To.Col, + }, + } +} From bd64c999c356d64afe7552bf77cb7836a24c5f37 Mon Sep 17 00:00:00 2001 From: Jackie Li Date: Mon, 15 Jul 2024 21:33:46 +0100 Subject: [PATCH 2/7] fix test and put templ symbols first --- cmd/templ/lspcmd/lsp_test.go | 46 +++++++++++++++++++++++++++----- cmd/templ/lspcmd/proxy/server.go | 7 ++++- 2 files changed, 46 insertions(+), 7 deletions(-) diff --git a/cmd/templ/lspcmd/lsp_test.go b/cmd/templ/lspcmd/lsp_test.go index 365d222da..d23285b5b 100644 --- a/cmd/templ/lspcmd/lsp_test.go +++ b/cmd/templ/lspcmd/lsp_test.go @@ -497,6 +497,23 @@ func TestDocumentSymbol(t *testing.T) { replacement: `
{ fmt.Sprintf("%d", count) }
`, cursor: ` ^`, expect: []any{ + protocol.SymbolInformation{ + Name: "Page(count int)", + Kind: protocol.SymbolKindFunction, + Location: protocol.Location{ + URI: uri.URI("file://" + appDir + "/templates.templ"), + Range: protocol.Range{ + Start: protocol.Position{ + Line: 4, + Character: 6, + }, + End: protocol.Position{ + Line: 4, + Character: 21, + }, + }, + }, + }, protocol.SymbolInformation{ Name: "nihao", Kind: protocol.SymbolKindVariable, @@ -515,18 +532,35 @@ func TestDocumentSymbol(t *testing.T) { }, }, protocol.SymbolInformation{ - Name: "Page(count int)", - Kind: protocol.SymbolKindFunction, + Name: "Struct", + Kind: protocol.SymbolKindStruct, Location: protocol.Location{ URI: uri.URI("file://" + appDir + "/templates.templ"), Range: protocol.Range{ Start: protocol.Position{ - Line: 4, - Character: 6, + Line: 20, + Character: 5, }, End: protocol.Position{ - Line: 4, - Character: 21, + Line: 22, + Character: 1, + }, + }, + }, + }, + protocol.SymbolInformation{ + Name: "s", + Kind: protocol.SymbolKindVariable, + Location: protocol.Location{ + URI: uri.URI("file://" + appDir + "/templates.templ"), + Range: protocol.Range{ + Start: protocol.Position{ + Line: 24, + Character: 4, + }, + End: protocol.Position{ + Line: 24, + Character: 16, }, }, }, diff --git a/cmd/templ/lspcmd/proxy/server.go b/cmd/templ/lspcmd/proxy/server.go index 854c13e1f..8bfff7026 100644 --- a/cmd/templ/lspcmd/proxy/server.go +++ b/cmd/templ/lspcmd/proxy/server.go @@ -777,6 +777,7 @@ func (p *Server) DocumentSymbol(ctx context.Context, params *lsp.DocumentSymbolP // TODO: it looks like we only have SymbolInformation in the result. We should handle DocumentSymbol as well. _ = requireDocumentSymbols + templSymbols := []interface{}{} doc, ok := p.TemplSource.Get(string(params.TextDocument.URI)) if ok { template, err := parser.ParseString(doc.String()) @@ -785,7 +786,7 @@ func (p *Server) DocumentSymbol(ctx context.Context, params *lsp.DocumentSymbolP switch s := s.(type) { case parser.TemplateFileGoExpression: case parser.HTMLTemplate: - result = append(result, lsp.SymbolInformation{ + templSymbols = append(templSymbols, lsp.SymbolInformation{ Name: s.Expression.Value, Kind: lsp.SymbolKindFunction, Location: lsp.Location{ @@ -799,6 +800,10 @@ func (p *Server) DocumentSymbol(ctx context.Context, params *lsp.DocumentSymbolP } } } + // Put the templ symbols first. + if len(templSymbols) > 0 { + result = append(templSymbols, result...) + } return result, err } From ac972905fa2af7a1a2be090f73ee0757556a3be2 Mon Sep 17 00:00:00 2001 From: Jackie Li Date: Mon, 15 Jul 2024 21:54:59 +0100 Subject: [PATCH 3/7] check error --- cmd/templ/lspcmd/lsp_test.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/cmd/templ/lspcmd/lsp_test.go b/cmd/templ/lspcmd/lsp_test.go index d23285b5b..e19853bda 100644 --- a/cmd/templ/lspcmd/lsp_test.go +++ b/cmd/templ/lspcmd/lsp_test.go @@ -614,6 +614,9 @@ func TestDocumentSymbol(t *testing.T) { func sliceToAnySlice(in []any) ([]any, error) { b, err := json.Marshal(in) + if err != nil { + return nil, err + } out := make([]any, 0, len(in)) err = json.Unmarshal(b, &out) return out, err From a9ca1f41098cd3bd4d28677c2d7eb1ce70771d8a Mon Sep 17 00:00:00 2001 From: Jackie Li Date: Mon, 21 Oct 2024 13:32:22 +0100 Subject: [PATCH 4/7] map to go source and back for ranges --- cmd/templ/lspcmd/lsp_test.go | 10 +++--- cmd/templ/lspcmd/proxy/server.go | 59 ++++++++++++++------------------ 2 files changed, 30 insertions(+), 39 deletions(-) diff --git a/cmd/templ/lspcmd/lsp_test.go b/cmd/templ/lspcmd/lsp_test.go index a257343c2..0e12792e3 100644 --- a/cmd/templ/lspcmd/lsp_test.go +++ b/cmd/templ/lspcmd/lsp_test.go @@ -659,18 +659,18 @@ func TestDocumentSymbol(t *testing.T) { cursor: ` ^`, expect: []any{ protocol.SymbolInformation{ - Name: "Page(count int)", + Name: "Page", Kind: protocol.SymbolKindFunction, Location: protocol.Location{ URI: uri.URI("file://" + appDir + "/templates.templ"), Range: protocol.Range{ Start: protocol.Position{ - Line: 4, - Character: 6, + Line: 11, + Character: 0, }, End: protocol.Position{ - Line: 4, - Character: 21, + Line: 50, + Character: 1, }, }, }, diff --git a/cmd/templ/lspcmd/proxy/server.go b/cmd/templ/lspcmd/proxy/server.go index 731685629..661ca3138 100644 --- a/cmd/templ/lspcmd/proxy/server.go +++ b/cmd/templ/lspcmd/proxy/server.go @@ -826,11 +826,27 @@ func (p *Server) DocumentLinkResolve(ctx context.Context, params *lsp.DocumentLi func (p *Server) DocumentSymbol(ctx context.Context, params *lsp.DocumentSymbolParams) (result []interface{} /* []SymbolInformation | []DocumentSymbol */, err error) { p.Log.Info("client -> server: DocumentSymbol") defer p.Log.Info("client -> server: DocumentSymbol end") + isTemplFile, goURI := convertTemplToGoURI(params.TextDocument.URI) + if !isTemplFile { + return p.Target.DocumentSymbol(ctx, params) + } + templURI := params.TextDocument.URI + params.TextDocument.URI = goURI symbols, err := p.Target.DocumentSymbol(ctx, params) if err != nil { return nil, err } - requireDocumentSymbols := false + + // recursively convert the ranges of the symbols and their children + var convertRange func(s *lsp.DocumentSymbol) + convertRange = func(s *lsp.DocumentSymbol) { + s.Range = p.convertGoRangeToTemplRange(templURI, s.Range) + s.SelectionRange = p.convertGoRangeToTemplRange(templURI, s.SelectionRange) + for i := 0; i < len(s.Children); i++ { + convertRange(&s.Children[i]) + } + } + for _, s := range symbols { if m, ok := s.(map[string]interface{}); ok { s, err = mapToSymbol(m) @@ -838,44 +854,19 @@ func (p *Server) DocumentSymbol(ctx context.Context, params *lsp.DocumentSymbolP return nil, err } } - switch s.(type) { + switch s := s.(type) { case lsp.DocumentSymbol: - requireDocumentSymbols = true + convertRange(&s) + result = append(result, s) case lsp.SymbolInformation: + // p.Log.Info("symbole range before", zap.Any("range", s.Location.Range), zap.String("uri", string(s.Location.URI))) + s.Location.URI = templURI + s.Location.Range = p.convertGoRangeToTemplRange(templURI, s.Location.Range) + // p.Log.Info("symbole range after", zap.Any("range", s.Location.Range), zap.String("uri", string(s.Location.URI))) + result = append(result, s) } - result = append(result, s) } - // TODO: it looks like we only have SymbolInformation in the result. We should handle DocumentSymbol as well. - _ = requireDocumentSymbols - - templSymbols := []interface{}{} - doc, ok := p.TemplSource.Get(string(params.TextDocument.URI)) - if ok { - template, err := parser.ParseString(doc.String()) - if err == nil { - for _, s := range template.Nodes { - switch s := s.(type) { - case parser.TemplateFileGoExpression: - case parser.HTMLTemplate: - templSymbols = append(templSymbols, lsp.SymbolInformation{ - Name: s.Expression.Value, - Kind: lsp.SymbolKindFunction, - Location: lsp.Location{ - URI: params.TextDocument.URI, - Range: parserRangeToLspRange(s.Expression.Range), - }, - }) - case parser.CSSTemplate: - case parser.ScriptTemplate: - } - } - } - } - // Put the templ symbols first. - if len(templSymbols) > 0 { - result = append(templSymbols, result...) - } return result, err } From db8eb869cf3bce1d5327b0ba8d2f9d06659cc022 Mon Sep 17 00:00:00 2001 From: Jackie Li Date: Mon, 21 Oct 2024 13:38:19 +0100 Subject: [PATCH 5/7] remove unused function --- cmd/templ/lspcmd/proxy/server.go | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/cmd/templ/lspcmd/proxy/server.go b/cmd/templ/lspcmd/proxy/server.go index 661ca3138..638b880a8 100644 --- a/cmd/templ/lspcmd/proxy/server.go +++ b/cmd/templ/lspcmd/proxy/server.go @@ -1277,16 +1277,3 @@ func mapToSymbol(m map[string]interface{}) (interface{}, error) { } return s, nil } - -func parserRangeToLspRange(r parser.Range) lsp.Range { - return lsp.Range{ - Start: lsp.Position{ - Line: r.From.Line, - Character: r.From.Col, - }, - End: lsp.Position{ - Line: r.To.Line, - Character: r.To.Col, - }, - } -} From 78c194aeb376412f081b18b13be8b44ff2e63b7c Mon Sep 17 00:00:00 2001 From: Jackie Li Date: Mon, 21 Oct 2024 16:34:48 +0100 Subject: [PATCH 6/7] improve document symbol test --- cmd/templ/lspcmd/lsp_test.go | 139 ++++++++++++----------------------- 1 file changed, 47 insertions(+), 92 deletions(-) diff --git a/cmd/templ/lspcmd/lsp_test.go b/cmd/templ/lspcmd/lsp_test.go index 0e12792e3..2f3ef995d 100644 --- a/cmd/templ/lspcmd/lsp_test.go +++ b/cmd/templ/lspcmd/lsp_test.go @@ -611,11 +611,7 @@ func TestDocumentSymbol(t *testing.T) { } ctx, cancel := context.WithCancel(context.Background()) - log := zap.NewNop() - // log, err := zap.NewDevelopment() - // if err != nil { - // t.Fatalf("failed to create logger: %v", err) - // } + log, _ := zap.NewProduction() ctx, appDir, _, server, teardown, err := Setup(ctx, log) if err != nil { @@ -624,54 +620,20 @@ func TestDocumentSymbol(t *testing.T) { defer teardown(t) defer cancel() - templFile, err := os.ReadFile(appDir + "/templates.templ") - if err != nil { - t.Fatalf("failed to read file %q: %v", appDir+"/templates.templ", err) - } - err = server.DidOpen(ctx, &protocol.DidOpenTextDocumentParams{ - TextDocument: protocol.TextDocumentItem{ - URI: uri.URI("file://" + appDir + "/templates.templ"), - LanguageID: "templ", - Version: 1, - Text: string(templFile), - }, - }) - if err != nil { - t.Errorf("failed to register open file: %v", err) - return - } - log.Info("Calling hover") - - // Edit the file. - // Replace: - //
{ fmt.Sprintf("%d", count) }
- // With various tests: - //
{ f tests := []struct { - line int - replacement string - cursor string - expect []any + uri string + expect []any }{ { - line: 13, - replacement: `
{ fmt.Sprintf("%d", count) }
`, - cursor: ` ^`, + uri: "file://" + appDir + "/templates.templ", expect: []any{ protocol.SymbolInformation{ Name: "Page", Kind: protocol.SymbolKindFunction, Location: protocol.Location{ - URI: uri.URI("file://" + appDir + "/templates.templ"), Range: protocol.Range{ - Start: protocol.Position{ - Line: 11, - Character: 0, - }, - End: protocol.Position{ - Line: 50, - Character: 1, - }, + Start: protocol.Position{Line: 11, Character: 0}, + End: protocol.Position{Line: 50, Character: 1}, }, }, }, @@ -679,16 +641,9 @@ func TestDocumentSymbol(t *testing.T) { Name: "nihao", Kind: protocol.SymbolKindVariable, Location: protocol.Location{ - URI: uri.URI("file://" + appDir + "/templates.templ"), Range: protocol.Range{ - Start: protocol.Position{ - Line: 18, - Character: 4, - }, - End: protocol.Position{ - Line: 18, - Character: 16, - }, + Start: protocol.Position{Line: 18, Character: 4}, + End: protocol.Position{Line: 18, Character: 16}, }, }, }, @@ -696,16 +651,9 @@ func TestDocumentSymbol(t *testing.T) { Name: "Struct", Kind: protocol.SymbolKindStruct, Location: protocol.Location{ - URI: uri.URI("file://" + appDir + "/templates.templ"), Range: protocol.Range{ - Start: protocol.Position{ - Line: 20, - Character: 5, - }, - End: protocol.Position{ - Line: 22, - Character: 1, - }, + Start: protocol.Position{Line: 20, Character: 5}, + End: protocol.Position{Line: 22, Character: 1}, }, }, }, @@ -713,54 +661,61 @@ func TestDocumentSymbol(t *testing.T) { Name: "s", Kind: protocol.SymbolKindVariable, Location: protocol.Location{ - URI: uri.URI("file://" + appDir + "/templates.templ"), Range: protocol.Range{ - Start: protocol.Position{ - Line: 24, - Character: 4, - }, - End: protocol.Position{ - Line: 24, - Character: 16, - }, + Start: protocol.Position{Line: 24, Character: 4}, + End: protocol.Position{Line: 24, Character: 16}, }, }, }, }, }, - } - - for i, test := range tests { - t.Run(fmt.Sprintf("test-%d", i), func(t *testing.T) { - // Put the file back to the initial point. - err = server.DidChange(ctx, &protocol.DidChangeTextDocumentParams{ - TextDocument: protocol.VersionedTextDocumentIdentifier{ - TextDocumentIdentifier: protocol.TextDocumentIdentifier{ - URI: uri.URI("file://" + appDir + "/templates.templ"), + { + uri: "file://" + appDir + "/remoteparent.templ", + expect: []any{ + protocol.SymbolInformation{ + Name: "RemoteInclusionTest", + Kind: protocol.SymbolKindFunction, + Location: protocol.Location{ + Range: protocol.Range{ + Start: protocol.Position{Line: 9, Character: 0}, + End: protocol.Position{Line: 35, Character: 1}, + }, }, - Version: int32(i + 2), }, - ContentChanges: []protocol.TextDocumentContentChangeEvent{ - { - Range: nil, - Text: string(templFile), + protocol.SymbolInformation{ + Name: "Remote2", + Kind: protocol.SymbolKindFunction, + Location: protocol.Location{ + Range: protocol.Range{ + Start: protocol.Position{Line: 37, Character: 0}, + End: protocol.Position{Line: 63, Character: 1}, + }, }, }, - }) - if err != nil { - t.Errorf("failed to change file: %v", err) - return - } + }, + }, + } - // Give CI/CD pipeline executors some time because they're often quite slow. + for i, test := range tests { + t.Run(fmt.Sprintf("test-%d", i), func(t *testing.T) { actual, err := server.DocumentSymbol(ctx, &protocol.DocumentSymbolParams{ TextDocument: protocol.TextDocumentIdentifier{ - URI: uri.URI("file://" + appDir + "/templates.templ"), + URI: uri.URI(test.uri), }, }) if err != nil { t.Errorf("failed to get document symbol: %v", err) } + + // set expected URI + for i := range test.expect { + switch v := test.expect[i].(type) { + case protocol.SymbolInformation: + v.Location.URI = uri.URI(test.uri) + test.expect[i] = v + } + } + expectdSlice, err := sliceToAnySlice(test.expect) if err != nil { t.Errorf("failed to convert expect to any slice: %v", err) From c54b04a87dd28d07b7c53b6a5944e6a51ec7e95b Mon Sep 17 00:00:00 2001 From: Jackie Li Date: Mon, 4 Nov 2024 14:58:14 +0000 Subject: [PATCH 7/7] remove debug logging --- cmd/templ/lspcmd/proxy/server.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/cmd/templ/lspcmd/proxy/server.go b/cmd/templ/lspcmd/proxy/server.go index 638b880a8..6599e17ce 100644 --- a/cmd/templ/lspcmd/proxy/server.go +++ b/cmd/templ/lspcmd/proxy/server.go @@ -859,10 +859,8 @@ func (p *Server) DocumentSymbol(ctx context.Context, params *lsp.DocumentSymbolP convertRange(&s) result = append(result, s) case lsp.SymbolInformation: - // p.Log.Info("symbole range before", zap.Any("range", s.Location.Range), zap.String("uri", string(s.Location.URI))) s.Location.URI = templURI s.Location.Range = p.convertGoRangeToTemplRange(templURI, s.Location.Range) - // p.Log.Info("symbole range after", zap.Any("range", s.Location.Range), zap.String("uri", string(s.Location.URI))) result = append(result, s) } }