diff --git a/CHANGELOG.md b/CHANGELOG.md index 8bca189..fa7bd91 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ # Changelog +## Unreleased +- 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) - Updates version constraints to support running on dart 3 diff --git a/lib/src/scip_visitor.dart b/lib/src/scip_visitor.dart index c1d1156..aa954fa 100644 --- a/lib/src/scip_visitor.dart +++ b/lib/src/scip_visitor.dart @@ -143,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), + )); } } } @@ -179,6 +180,7 @@ class ScipVisitor extends GeneralizingAstVisitor { symbol: symbol, symbolRoles: SymbolRole.Definition.value, diagnostics: meta.diagnostics, + enclosingRange: _lineInfo.getRange(node.offset, node.end), )); } } diff --git a/lib/src/utils.dart b/lib/src/utils.dart index dd0eb01..ba08682 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; } }