From 2969b02e488b5669f3becf1f3665fc727f0cddd5 Mon Sep 17 00:00:00 2001 From: Matthew Nitschke Date: Sat, 27 Sep 2025 15:55:45 -0600 Subject: [PATCH 1/4] populate enclosing range --- lib/src/scip_visitor.dart | 2 ++ lib/src/utils.dart | 22 +++++++++++++++++----- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/lib/src/scip_visitor.dart b/lib/src/scip_visitor.dart index c1d1156c..af6b5956 100644 --- a/lib/src/scip_visitor.dart +++ b/lib/src/scip_visitor.dart @@ -135,6 +135,7 @@ class ScipVisitor extends GeneralizingAstVisitor { range: _lineInfo.getRange(offset, length), symbol: symbol, diagnostics: meta.diagnostics, + enclosingRange: _lineInfo.getRange(node.parent!.offset, node.parent!.length) )); if (!element.source!.fullName.startsWith(_projectRoot)) { @@ -179,6 +180,7 @@ class ScipVisitor extends GeneralizingAstVisitor { symbol: symbol, symbolRoles: SymbolRole.Definition.value, diagnostics: meta.diagnostics, + enclosingRange: _lineInfo.getRange(node.parent!.offset, node.parent!.length) )); } } diff --git a/lib/src/utils.dart b/lib/src/utils.dart index dd0eb01a..ba086821 100644 --- a/lib/src/utils.dart +++ b/lib/src/utils.dart @@ -34,12 +34,24 @@ void display(String input, {DisplayLevel level = DisplayLevel.warn}) { extension LineInfoExtension on LineInfo { List getRange(int offset, int nameLength) { - final loc = getLocation(offset); - return [ - loc.lineNumber - 1, - loc.columnNumber - 1, - loc.columnNumber - 1 + nameLength + final start = getLocation(offset); + final end = getLocation(offset + nameLength); + + final res = [ + start.lineNumber - 1, + start.columnNumber - 1, + end.lineNumber - 1, + end.columnNumber - 1, ]; + + // if the range starts and ends on the same line, only return + // 3 elements, where the first is the line number, and the others + // are startCol and endCol. This is apart of the scip spec + if (res[0] == res[2]) { + res.removeAt(2); + } + + return res; } } From ff8dbf72f987bcd5dc16874b73139205b1830836 Mon Sep 17 00:00:00 2001 From: Matthew Nitschke Date: Sat, 27 Sep 2025 16:01:11 -0600 Subject: [PATCH 2/4] fmt --- lib/src/scip_visitor.dart | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/lib/src/scip_visitor.dart b/lib/src/scip_visitor.dart index af6b5956..0a0ad4bb 100644 --- a/lib/src/scip_visitor.dart +++ b/lib/src/scip_visitor.dart @@ -132,11 +132,11 @@ class ScipVisitor extends GeneralizingAstVisitor { if (symbol != null) { final meta = getSymbolMetadata(element, offset, _analysisErrors); occurrences.add(Occurrence( - range: _lineInfo.getRange(offset, length), - symbol: symbol, - diagnostics: meta.diagnostics, - enclosingRange: _lineInfo.getRange(node.parent!.offset, node.parent!.length) - )); + range: _lineInfo.getRange(offset, length), + symbol: symbol, + diagnostics: meta.diagnostics, + enclosingRange: + _lineInfo.getRange(node.parent!.offset, node.parent!.length))); if (!element.source!.fullName.startsWith(_projectRoot)) { if (!globalExternalSymbols.any( @@ -176,11 +176,11 @@ class ScipVisitor extends GeneralizingAstVisitor { )); occurrences.add(Occurrence( - range: _lineInfo.getRange(element.nameOffset, element.nameLength), - symbol: symbol, - symbolRoles: SymbolRole.Definition.value, - diagnostics: meta.diagnostics, - enclosingRange: _lineInfo.getRange(node.parent!.offset, node.parent!.length) - )); + range: _lineInfo.getRange(element.nameOffset, element.nameLength), + symbol: symbol, + symbolRoles: SymbolRole.Definition.value, + diagnostics: meta.diagnostics, + enclosingRange: + _lineInfo.getRange(node.parent!.offset, node.parent!.length))); } } From 3f184fdc74d6141e97cb40f2c8da6f05ce72cb08 Mon Sep 17 00:00:00 2001 From: Matthew Nitschke Date: Sat, 27 Sep 2025 16:01:54 -0600 Subject: [PATCH 3/4] updated changelog --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8bca189c..d6452663 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ # Changelog +## Unreleased +- Added support for `enclosing_range` on symbol occurrences + ## 1.6.2 - Fixed a few minor bugs found in pubspec.yaml indexing (skips publish_to: none pubspecs, and considers "version" optional) - Updates version constraints to support running on dart 3 From 9d6e59a3780458e29d1178e46acf20f0cae1e238 Mon Sep 17 00:00:00 2001 From: Matthew Nitschke Date: Mon, 29 Sep 2025 17:24:41 -0600 Subject: [PATCH 4/4] fixed incorrect range calculation --- CHANGELOG.md | 2 +- lib/src/scip_visitor.dart | 30 +++++++++++++++--------------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d6452663..fa7bd914 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,7 @@ # Changelog ## Unreleased -- Added support for `enclosing_range` on symbol occurrences +- Added support for `enclosing_range` on occurrences definitions ## 1.6.2 - Fixed a few minor bugs found in pubspec.yaml indexing (skips publish_to: none pubspecs, and considers "version" optional) diff --git a/lib/src/scip_visitor.dart b/lib/src/scip_visitor.dart index 0a0ad4bb..aa954fae 100644 --- a/lib/src/scip_visitor.dart +++ b/lib/src/scip_visitor.dart @@ -132,11 +132,10 @@ class ScipVisitor extends GeneralizingAstVisitor { if (symbol != null) { final meta = getSymbolMetadata(element, offset, _analysisErrors); occurrences.add(Occurrence( - range: _lineInfo.getRange(offset, length), - symbol: symbol, - diagnostics: meta.diagnostics, - enclosingRange: - _lineInfo.getRange(node.parent!.offset, node.parent!.length))); + range: _lineInfo.getRange(offset, length), + symbol: symbol, + diagnostics: meta.diagnostics, + )); if (!element.source!.fullName.startsWith(_projectRoot)) { if (!globalExternalSymbols.any( @@ -144,10 +143,11 @@ class ScipVisitor extends GeneralizingAstVisitor { )) { final meta = getSymbolMetadata(element, offset, _analysisErrors); globalExternalSymbols.add(SymbolInformation( - symbol: symbol, - documentation: meta.documentation, - signatureDocumentation: meta.signatureDocumentation, - kind: symbolKindFor(element))); + symbol: symbol, + documentation: meta.documentation, + signatureDocumentation: meta.signatureDocumentation, + kind: symbolKindFor(element), + )); } } } @@ -176,11 +176,11 @@ class ScipVisitor extends GeneralizingAstVisitor { )); occurrences.add(Occurrence( - range: _lineInfo.getRange(element.nameOffset, element.nameLength), - symbol: symbol, - symbolRoles: SymbolRole.Definition.value, - diagnostics: meta.diagnostics, - enclosingRange: - _lineInfo.getRange(node.parent!.offset, node.parent!.length))); + range: _lineInfo.getRange(element.nameOffset, element.nameLength), + symbol: symbol, + symbolRoles: SymbolRole.Definition.value, + diagnostics: meta.diagnostics, + enclosingRange: _lineInfo.getRange(node.offset, node.end), + )); } }