Skip to content

Commit f6c125d

Browse files
Merge pull request #193 from Workiva/populate_enclosing_range
FEDX-4020: Populate enclosing_range
2 parents d1c3a82 + 9d6e59a commit f6c125d

File tree

3 files changed

+26
-9
lines changed

3 files changed

+26
-9
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Changelog
22

3+
## Unreleased
4+
- Added support for `enclosing_range` on occurrences definitions
5+
36
## 1.6.2
47
- Fixed a few minor bugs found in pubspec.yaml indexing (skips publish_to: none pubspecs, and considers "version" optional)
58
- Updates version constraints to support running on dart 3

lib/src/scip_visitor.dart

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -143,10 +143,11 @@ class ScipVisitor extends GeneralizingAstVisitor {
143143
)) {
144144
final meta = getSymbolMetadata(element, offset, _analysisErrors);
145145
globalExternalSymbols.add(SymbolInformation(
146-
symbol: symbol,
147-
documentation: meta.documentation,
148-
signatureDocumentation: meta.signatureDocumentation,
149-
kind: symbolKindFor(element)));
146+
symbol: symbol,
147+
documentation: meta.documentation,
148+
signatureDocumentation: meta.signatureDocumentation,
149+
kind: symbolKindFor(element),
150+
));
150151
}
151152
}
152153
}
@@ -179,6 +180,7 @@ class ScipVisitor extends GeneralizingAstVisitor {
179180
symbol: symbol,
180181
symbolRoles: SymbolRole.Definition.value,
181182
diagnostics: meta.diagnostics,
183+
enclosingRange: _lineInfo.getRange(node.offset, node.end),
182184
));
183185
}
184186
}

lib/src/utils.dart

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,24 @@ void display(String input, {DisplayLevel level = DisplayLevel.warn}) {
3434

3535
extension LineInfoExtension on LineInfo {
3636
List<int> getRange(int offset, int nameLength) {
37-
final loc = getLocation(offset);
38-
return [
39-
loc.lineNumber - 1,
40-
loc.columnNumber - 1,
41-
loc.columnNumber - 1 + nameLength
37+
final start = getLocation(offset);
38+
final end = getLocation(offset + nameLength);
39+
40+
final res = [
41+
start.lineNumber - 1,
42+
start.columnNumber - 1,
43+
end.lineNumber - 1,
44+
end.columnNumber - 1,
4245
];
46+
47+
// if the range starts and ends on the same line, only return
48+
// 3 elements, where the first is the line number, and the others
49+
// are startCol and endCol. This is apart of the scip spec
50+
if (res[0] == res[2]) {
51+
res.removeAt(2);
52+
}
53+
54+
return res;
4355
}
4456
}
4557

0 commit comments

Comments
 (0)