diff --git a/pkg/analysis_server/test/lsp/folding_test.dart b/pkg/analysis_server/test/lsp/folding_test.dart index c0b69cfe23b..ef42036ddc5 100644 --- a/pkg/analysis_server/test/lsp/folding_test.dart +++ b/pkg/analysis_server/test/lsp/folding_test.dart @@ -50,7 +50,7 @@ class FoldingTest extends AbstractLspAnalysisServerTest { void expectRanges(Map expected, {bool requireAll = true}) { final expectedRanges = expected.entries.map((entry) { - final range = code.ranges[entry.key].lsp; + final range = code.ranges[entry.key].range; return FoldingRange( startLine: range.start.line, startCharacter: lineFoldingOnly ? null : range.start.character, diff --git a/pkg/analysis_server/test/lsp/type_hierarchy_test.dart b/pkg/analysis_server/test/lsp/type_hierarchy_test.dart index ded1ed07af2..6d9d4d7b573 100644 --- a/pkg/analysis_server/test/lsp/type_hierarchy_test.dart +++ b/pkg/analysis_server/test/lsp/type_hierarchy_test.dart @@ -91,7 +91,7 @@ abstract class AbstractTypeHierarchyTest extends AbstractLspAnalysisServerTest { await initialize(); final result = await prepareTypeHierarchy( mainFileUri, - code.position.lsp, + code.position.position, ); prepareResult = result?.singleOrNull; } @@ -109,8 +109,8 @@ class PrepareTypeHierarchyTest extends AbstractTypeHierarchyTest { _isItem( 'MyClass1', mainFileUri, - range: code.ranges[0].lsp, - selectionRange: code.ranges[1].lsp, + range: code.ranges[0].range, + selectionRange: code.ranges[1].range, ), ); } @@ -155,8 +155,8 @@ import 'main.dart'; 'MyClass2', otherFileUri, detail: 'extends', - range: otherCode.ranges[0].lsp, - selectionRange: otherCode.ranges[1].lsp, + range: otherCode.ranges[0].range, + selectionRange: otherCode.ranges[1].range, ), ])); } @@ -174,8 +174,8 @@ class MyCla^ss1 {} 'MyClass2', mainFileUri, detail: 'extends', - range: code.ranges[0].lsp, - selectionRange: code.ranges[1].lsp, + range: code.ranges[0].range, + selectionRange: code.ranges[1].range, ), ])); } @@ -193,8 +193,8 @@ class MyCla^ss1 {} 'MyClass2', mainFileUri, detail: 'implements', - range: code.ranges[0].lsp, - selectionRange: code.ranges[1].lsp, + range: code.ranges[0].range, + selectionRange: code.ranges[1].range, ), ])); } @@ -212,8 +212,8 @@ class MyCla^ss1 {} 'MyMixin1', mainFileUri, detail: 'constrained to', - range: code.ranges[0].lsp, - selectionRange: code.ranges[1].lsp, + range: code.ranges[0].range, + selectionRange: code.ranges[1].range, ), ])); } @@ -231,8 +231,8 @@ mixin MyMi^xin1 {} 'MyClass1', mainFileUri, detail: 'mixes in', - range: code.ranges[0].lsp, - selectionRange: code.ranges[1].lsp, + range: code.ranges[0].range, + selectionRange: code.ranges[1].range, ), ])); } @@ -266,8 +266,8 @@ class MyCla^ss2 extends MyClass1 {} 'MyClass1', otherFileUri, detail: 'extends', - range: otherCode.ranges[0].lsp, - selectionRange: otherCode.ranges[1].lsp, + range: otherCode.ranges[0].range, + selectionRange: otherCode.ranges[1].range, ), ])); } @@ -285,8 +285,8 @@ class MyCla^ss2 extends MyClass1 {} 'MyClass1', mainFileUri, detail: 'extends', - range: code.ranges[0].lsp, - selectionRange: code.ranges[1].lsp, + range: code.ranges[0].range, + selectionRange: code.ranges[1].range, ), ])); } @@ -305,8 +305,8 @@ class MyCla^ss2 implements MyClass1 {} 'MyClass1', mainFileUri, detail: 'implements', - range: code.ranges[0].lsp, - selectionRange: code.ranges[1].lsp, + range: code.ranges[0].range, + selectionRange: code.ranges[1].range, ), ])); } @@ -324,8 +324,8 @@ mixin MyMix^in1 on MyClass1 {} 'MyClass1', mainFileUri, detail: 'constrained to', - range: code.ranges[0].lsp, - selectionRange: code.ranges[1].lsp, + range: code.ranges[0].range, + selectionRange: code.ranges[1].range, ), ])); } @@ -344,8 +344,8 @@ class MyCla^ss1 with MyMixin1 {} 'MyMixin1', mainFileUri, detail: 'mixes in', - range: code.ranges[0].lsp, - selectionRange: code.ranges[1].lsp, + range: code.ranges[0].range, + selectionRange: code.ranges[1].range, ), ])); } diff --git a/pkg/analysis_server/test/test_code_format_test.dart b/pkg/analysis_server/test/test_code_format_test.dart index 419ed979805..a4fd030d997 100644 --- a/pkg/analysis_server/test/test_code_format_test.dart +++ b/pkg/analysis_server/test/test_code_format_test.dart @@ -31,8 +31,8 @@ int a = 1 expect(code.positions, hasLength(1)); expect(code.position.offset, 4); expect(code.position.offset, code.positions[0].offset); - expect(code.position.lsp, lsp.Position(line: 0, character: 4)); - expect(code.position.lsp, code.positions[0].lsp); + expect(code.position.position, lsp.Position(line: 0, character: 4)); + expect(code.position.position, code.positions[0].position); expect(code.ranges, isEmpty); } @@ -62,8 +62,8 @@ String a = '^^^'; expect(code.positions, hasLength(1)); expect(code.position.offset, 7); expect(code.position.offset, code.positions[0].offset); - expect(code.position.lsp, lsp.Position(line: 0, character: 7)); - expect(code.position.lsp, code.positions[0].lsp); + expect(code.position.position, lsp.Position(line: 0, character: 7)); + expect(code.position.position, code.positions[0].position); expect(code.ranges, isEmpty); } @@ -86,9 +86,9 @@ int b = 2; expect(code.positions[1].offset, 10); expect(code.positions[2].offset, 16); - expect(code.positions[0].lsp, lsp.Position(line: 0, character: 4)); - expect(code.positions[1].lsp, lsp.Position(line: 0, character: 10)); - expect(code.positions[2].lsp, lsp.Position(line: 1, character: 5)); + expect(code.positions[0].position, lsp.Position(line: 0, character: 4)); + expect(code.positions[1].position, lsp.Position(line: 0, character: 10)); + expect(code.positions[2].position, lsp.Position(line: 1, character: 5)); } void test_positions_reused() { @@ -130,12 +130,12 @@ int b = 2; expect(code.ranges[0].sourceRange, SourceRange(4, 6)); expect(code.ranges[1].sourceRange, SourceRange(11, 10)); expect( - code.ranges[0].lsp, + code.ranges[0].range, lsp.Range( start: lsp.Position(line: 0, character: 4), end: lsp.Position(line: 0, character: 10))); expect( - code.ranges[1].lsp, + code.ranges[1].range, lsp.Range( start: lsp.Position(line: 1, character: 0), end: lsp.Position(line: 1, character: 10))); diff --git a/pkg/analysis_server/test/utils/test_code_format.dart b/pkg/analysis_server/test/utils/test_code_format.dart index 925590524c1..a3e2664e2d4 100644 --- a/pkg/analysis_server/test/utils/test_code_format.dart +++ b/pkg/analysis_server/test/utils/test_code_format.dart @@ -121,10 +121,7 @@ class TestCode { final positions = positionOffsets.map( (number, offset) => MapEntry( number, - TestCodePosition( - offset, - toPosition(lineInfo.getLocation(offset)), - ), + TestCodePosition(lineInfo, offset), ), ); @@ -132,9 +129,9 @@ class TestCode { (number, offset) => MapEntry( number, TestCodeRange( + lineInfo, code.substring(offset, rangeEndOffsets[number]!), SourceRange(offset, rangeEndOffsets[number]! - offset), - toRange(lineInfo, offset, rangeEndOffsets[number]! - offset), ), ), ); @@ -150,20 +147,21 @@ class TestCode { /// A marked position in the test code. class TestCodePosition { + /// Line break information for the test code. + final LineInfo lineInfo; + /// The 0-based offset of the marker. /// /// Offsets are based on [TestCode.code], with all parsed markers removed. final int offset; - /// The LSP [Position] of the marker. - /// - /// Positions are based on [TestCode.code], with all parsed markers removed. - final Position lsp; - - TestCodePosition(this.offset, this.lsp); + TestCodePosition(this.lineInfo, this.offset); } class TestCodeRange { + /// Line break information for the test code. + final LineInfo lineInfo; + /// The text from [TestCode.code] covered by this range. final String text; @@ -173,10 +171,19 @@ class TestCodeRange { /// removed. final SourceRange sourceRange; + TestCodeRange(this.lineInfo, this.text, this.sourceRange); +} + +extension TestCodePositionExtension on TestCodePosition { + /// Return the LSP [Position] of the marker. + /// + /// Positions are based on [TestCode.code], with all parsed markers removed. + Position get position => toPosition(lineInfo.getLocation(offset)); +} + +extension TestCodeRangeExtension on TestCodeRange { /// The LSP [Range] indicated by the markers. /// /// Ranges are based on [TestCode.code], with all parsed markers removed. - final Range lsp; - - TestCodeRange(this.text, this.sourceRange, this.lsp); + Range get range => toRange(lineInfo, sourceRange.offset, sourceRange.length); }