-
-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(language-service): formatting range param not converted correctly (…
- Loading branch information
1 parent
8b74be8
commit b9da423
Showing
4 changed files
with
156 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
packages/language-service/tests/findOverlapCodeRange.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import { describe, expect, it } from 'vitest'; | ||
import { findOverlapCodeRange } from '../lib/utils/common'; | ||
import { CodeInformation, Mapping, SourceMap } from '@volar/language-core'; | ||
|
||
// test code: <html><body><p>Hello</p></body></html> | ||
|
||
describe(`Test findOverlapCodeRange()`, () => { | ||
|
||
it('signal mapping', () => { | ||
const mappings: Mapping<CodeInformation>[] = [ | ||
{ | ||
sourceOffsets: [0], | ||
generatedOffsets: [0], | ||
lengths: [38], | ||
data: { verification: true, completion: true, semantic: true, navigation: true, structure: true, format: true }, | ||
}, | ||
]; | ||
const map = new SourceMap(mappings); | ||
|
||
expect(findOverlapCodeRange(0, 38, map, () => true)).toEqual({ start: 0, end: 38 }); | ||
expect(findOverlapCodeRange(6, 31, map, () => true)).toEqual({ start: 6, end: 31 }); | ||
}); | ||
|
||
it('fallback to valid range', () => { | ||
const mappings: Mapping<CodeInformation>[] = [ | ||
{ | ||
sourceOffsets: [6], | ||
generatedOffsets: [6], | ||
lengths: [25], | ||
data: { verification: true, completion: true, semantic: true, navigation: true, structure: true, format: true }, | ||
}, | ||
]; | ||
const map = new SourceMap(mappings); | ||
|
||
expect(findOverlapCodeRange(5, 32, map, () => true)).toEqual({ start: 6, end: 31 }); | ||
expect(findOverlapCodeRange(7, 32, map, () => true)).toEqual({ start: 7, end: 31 }); | ||
expect(findOverlapCodeRange(5, 30, map, () => true)).toEqual({ start: 6, end: 30 }); | ||
}); | ||
|
||
it('fallback to valid range (offset)', () => { | ||
const mappings: Mapping<CodeInformation>[] = [ | ||
{ | ||
sourceOffsets: [6], | ||
generatedOffsets: [7], | ||
lengths: [25], | ||
data: { verification: true, completion: true, semantic: true, navigation: true, structure: true, format: true }, | ||
}, | ||
]; | ||
const map = new SourceMap(mappings); | ||
|
||
expect(findOverlapCodeRange(5, 32, map, () => true)).toEqual({ start: 7, end: 32 }); | ||
expect(findOverlapCodeRange(7, 32, map, () => true)).toEqual({ start: 8, end: 32 }); | ||
expect(findOverlapCodeRange(5, 30, map, () => true)).toEqual({ start: 7, end: 31 }); | ||
}); | ||
|
||
it('mutilple mappings', () => { | ||
const mappings: Mapping<CodeInformation>[] = [ | ||
{ | ||
sourceOffsets: [6], | ||
generatedOffsets: [6], | ||
lengths: [6], | ||
data: { verification: true, completion: true, semantic: true, navigation: true, structure: true, format: true }, | ||
}, | ||
{ | ||
sourceOffsets: [24], | ||
generatedOffsets: [24], | ||
lengths: [7], | ||
data: { verification: true, completion: true, semantic: true, navigation: true, structure: true, format: true }, | ||
}, | ||
]; | ||
const map = new SourceMap(mappings); | ||
|
||
expect(findOverlapCodeRange(0, 38, map, () => true)).toEqual({ start: 6, end: 31 }); | ||
}); | ||
}); |