Skip to content

Commit

Permalink
chore: remove duplicates
Browse files Browse the repository at this point in the history
  • Loading branch information
qvalentin committed Dec 15, 2024
1 parent 7bf68f5 commit b510415
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 15 deletions.
4 changes: 1 addition & 3 deletions internal/language_features/generic_template_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@ func (f *GenericTemplateContextFeature) getReferencesFromSymbolTable(templateCon

for _, doc := range f.GenericDocumentUseCase.DocumentStore.GetAllTemplateDocs() {
referenceRanges := doc.SymbolTable.GetTemplateContextRanges(templateContext)
for _, referenceRange := range referenceRanges {
locations = append(locations, util.RangeToLocation(doc.URI, referenceRange))
}
locations = append(locations, util.RangesToLocations(doc.URI, referenceRanges)...)
}

return locations
Expand Down
8 changes: 2 additions & 6 deletions internal/language_features/includes.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,7 @@ func (f *IncludesFeature) getReferenceLocations(includeName string) []lsp.Locati
locations := []lsp.Location{}
for _, doc := range f.GenericDocumentUseCase.DocumentStore.GetAllTemplateDocs() {
referenceRanges := doc.SymbolTable.GetIncludeReference(includeName)
for _, referenceRange := range referenceRanges {
locations = append(locations, util.RangeToLocation(doc.URI, referenceRange))
}
locations = append(locations, util.RangesToLocations(doc.URI, referenceRanges)...)
if len(locations) > 0 {
charts.SyncToDisk(doc)
}
Expand All @@ -103,9 +101,7 @@ func (f *IncludesFeature) getDefinitionLocations(includeName string) []lsp.Locat
locations := []lsp.Location{}
for _, doc := range f.GenericDocumentUseCase.DocumentStore.GetAllTemplateDocs() {
definitionRanges := doc.SymbolTable.GetIncludeDefinitions(includeName)
for _, definitionRange := range definitionRanges {
locations = append(locations, util.RangeToLocation(doc.URI, definitionRange))
}
locations = append(locations, util.RangesToLocations(doc.URI, definitionRanges)...)
if len(locations) > 0 {
charts.SyncToDisk(doc)
}
Expand Down
4 changes: 1 addition & 3 deletions internal/language_features/template_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,7 @@ func (f *TemplateContextFeature) getReferenceLocations(templateContext symboltab
locations := []lsp.Location{}
for _, doc := range f.GenericDocumentUseCase.DocumentStore.GetAllTemplateDocs() {
referenceRanges := doc.SymbolTable.GetTemplateContextRanges(templateContext)
for _, referenceRange := range referenceRanges {
locations = append(locations, util.RangeToLocation(doc.URI, referenceRange))
}
locations = append(locations, util.RangesToLocations(doc.URI, referenceRanges)...)
}

return append(locations, f.getDefinitionLocations(templateContext)...)
Expand Down
4 changes: 1 addition & 3 deletions internal/language_features/variables.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,7 @@ func (f *VariablesFeature) References() (result []lsp.Location, err error) {
return []lsp.Location{}, err
}

for _, reference := range variableReferences {
result = append(result, util.RangeToLocation(f.Document.URI, reference))
}
result = append(result, util.RangesToLocations(f.Document.URI, variableReferences)...)
return result, nil
}

Expand Down
7 changes: 7 additions & 0 deletions internal/util/points.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,10 @@ func RangeToLocation(URI uri.URI, range_ sitter.Range) lsp.Location {
},
}
}

func RangesToLocations(URI uri.URI, ranges []sitter.Range) (locations []lsp.Location) {
for _, definitionRange := range ranges {
locations = append(locations, RangeToLocation(URI, definitionRange))
}
return locations
}
Empty file added internal/util/points_test.go
Empty file.

0 comments on commit b510415

Please sign in to comment.