-
-
Notifications
You must be signed in to change notification settings - Fork 204
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
86230c7
commit aa81c16
Showing
23 changed files
with
249 additions
and
112 deletions.
There are no files selected for viewing
104 changes: 0 additions & 104 deletions
104
packages/language-server/test/plugins/typescript/features/FoldingRangeProvider.test.ts
This file was deleted.
Oops, something went wrong.
1 change: 1 addition & 0 deletions
1
packages/language-server/test/plugins/typescript/features/folding-range/.gitignore
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 @@ | ||
debug.svelte |
4 changes: 4 additions & 0 deletions
4
...erver/test/plugins/typescript/features/folding-range/fixtures/await-catch/expectedv2.json
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,4 @@ | ||
[ | ||
{ "startLine": 0, "endLine": 1 }, | ||
{ "startLine": 4, "endLine": 7 } | ||
] |
9 changes: 9 additions & 0 deletions
9
...e-server/test/plugins/typescript/features/folding-range/fixtures/await-catch/input.svelte
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,9 @@ | ||
{#await somePromise catch error} | ||
<h1>Promise Pending</h1> | ||
{/await} | ||
|
||
{#await somePromise | ||
|
||
catch error} | ||
<h1>Promise Pending</h1> | ||
{/await} |
4 changes: 4 additions & 0 deletions
4
...est/plugins/typescript/features/folding-range/fixtures/await-peding-catch/expectedv2.json
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,4 @@ | ||
[ | ||
{ "startLine": 0, "endLine": 1 }, | ||
{ "startLine": 6, "endLine": 7 } | ||
] |
12 changes: 12 additions & 0 deletions
12
...r/test/plugins/typescript/features/folding-range/fixtures/await-peding-catch/input.svelte
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,12 @@ | ||
{#await somePromise} | ||
<h1>Promise Pending</h1> | ||
{:catch error} | ||
<h1>Promise Errored {error}</h1> | ||
{/await} | ||
|
||
{#await somePromise} | ||
<h1>Promise Pending</h1> | ||
{ | ||
:catch error} | ||
<h1>Promise Errored {error}</h1> | ||
{/await} |
1 change: 1 addition & 0 deletions
1
...est/plugins/typescript/features/folding-range/fixtures/await-pending-only/expectedv2.json
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 @@ | ||
[] |
3 changes: 3 additions & 0 deletions
3
...r/test/plugins/typescript/features/folding-range/fixtures/await-pending-only/input.svelte
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,3 @@ | ||
{#await somePromise} | ||
<h1>Loading</h1> | ||
{/await} |
8 changes: 8 additions & 0 deletions
8
...ugins/typescript/features/folding-range/fixtures/await-pending-then-catch/expectedv2.json
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,8 @@ | ||
[ | ||
{ "startLine": 2, "endLine": 3 }, | ||
{ "startLine": 0, "endLine": 1 }, | ||
{ "startLine": 4, "endLine": 5 }, | ||
{ "startLine": 10, "endLine": 12 }, | ||
{ "startLine": 8, "endLine": 9 }, | ||
{ "startLine": 13, "endLine": 15 } | ||
] |
17 changes: 17 additions & 0 deletions
17
.../plugins/typescript/features/folding-range/fixtures/await-pending-then-catch/input.svelte
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,17 @@ | ||
{#await somePromise} | ||
<h1>Promise Pending</h1> | ||
{:then value} | ||
<h1>Promise Resolved {value}</h1> | ||
{:catch error} | ||
<h1>Promise Errored {error}</h1> | ||
{/await} | ||
|
||
{#await somePromise} | ||
<h1>Promise Pending</h1> | ||
{ | ||
:then value} | ||
<h1>Promise Resolved {value}</h1> | ||
{ | ||
:catch error} | ||
<h1>Promise Errored {error}</h1> | ||
{/await} |
1 change: 1 addition & 0 deletions
1
...est/plugins/typescript/features/folding-range/fixtures/await-pending-then/expectedv2.json
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 @@ | ||
[{ "startLine": 0, "endLine": 1 }] |
5 changes: 5 additions & 0 deletions
5
...r/test/plugins/typescript/features/folding-range/fixtures/await-pending-then/input.svelte
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,5 @@ | ||
{#await somePromise} | ||
<h1>Promise Pending</h1> | ||
{:catch error} | ||
<h1>Promise Errored {error}</h1> | ||
{/await} |
4 changes: 4 additions & 0 deletions
4
...server/test/plugins/typescript/features/folding-range/fixtures/await-then/expectedv2.json
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,4 @@ | ||
[ | ||
{ "startLine": 0, "endLine": 1 }, | ||
{ "startLine": 4, "endLine": 7 } | ||
] |
9 changes: 9 additions & 0 deletions
9
...ge-server/test/plugins/typescript/features/folding-range/fixtures/await-then/input.svelte
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,9 @@ | ||
{#await somePromise then value} | ||
<h1>Promise Pending</h1> | ||
{/await} | ||
|
||
{#await somePromise | ||
|
||
then value} | ||
<h1>Promise Pending</h1> | ||
{/await} |
4 changes: 4 additions & 0 deletions
4
...server/test/plugins/typescript/features/folding-range/fixtures/each-block/expectedv2.json
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,4 @@ | ||
[ | ||
{ "startLine": 0, "endLine": 1 }, | ||
{ "startLine": 4, "endLine": 5 } | ||
] |
9 changes: 9 additions & 0 deletions
9
...ge-server/test/plugins/typescript/features/folding-range/fixtures/each-block/input.svelte
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,9 @@ | ||
{#each items as item} | ||
{item} | ||
{/each} | ||
|
||
{#each items as item} | ||
{item} | ||
{:else} | ||
no items | ||
{/each} |
8 changes: 8 additions & 0 deletions
8
...e-server/test/plugins/typescript/features/folding-range/fixtures/if-block/expectedv2.json
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,8 @@ | ||
[ | ||
{ "startLine": 0, "endLine": 1 }, | ||
{ "startLine": 2, "endLine": 3 }, | ||
{ "startLine": 4, "endLine": 5 }, | ||
{ "startLine": 8, "endLine": 9 }, | ||
{ "startLine": 12, "endLine": 13 }, | ||
{ "startLine": 14, "endLine": 15 } | ||
] |
17 changes: 17 additions & 0 deletions
17
...uage-server/test/plugins/typescript/features/folding-range/fixtures/if-block/input.svelte
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,17 @@ | ||
{#if name1 == "world"} | ||
<h1>Hello {name2}</h1> | ||
{:else if name3 == "person"} | ||
<h2>hello {name4}</h2> | ||
{:else} | ||
<h3>hey {name5}</h3> | ||
{/if} | ||
|
||
{#if kenobi} | ||
<h2>Hello There</h2> | ||
{/if} | ||
|
||
{#if name1 = 'hi'} | ||
<h2>hi</h2> | ||
{:else} | ||
<h3>hello</h3> | ||
{/if} |
5 changes: 5 additions & 0 deletions
5
...rver/test/plugins/typescript/features/folding-range/fixtures/parser-error/expectedv2.json
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,5 @@ | ||
[ | ||
{ "startLine": 1, "endLine": 2 }, | ||
{ "startLine": 6, "endLine": 7 }, | ||
{ "startLine": 8, "endLine": 9 } | ||
] |
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 |
---|---|---|
|
@@ -8,4 +8,4 @@ | |
<div></div> | ||
{:else} | ||
<div></div> | ||
{/if} | ||
{/if |
4 changes: 4 additions & 0 deletions
4
...age-server/test/plugins/typescript/features/folding-range/fixtures/script/expectedv2.json
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,4 @@ | ||
[ | ||
{ "startLine": 1, "endLine": 2, "kind": "imports" }, | ||
{ "startLine": 4, "endLine": 5 } | ||
] |
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 |
---|---|---|
|
@@ -5,10 +5,4 @@ | |
function hi() { | ||
} | ||
</script> | ||
|
||
{#if 'hi'} | ||
<div></div> | ||
{:else} | ||
<div></div> | ||
{/if} | ||
</script> |
122 changes: 122 additions & 0 deletions
122
packages/language-server/test/plugins/typescript/features/folding-range/index.test.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,122 @@ | ||
import * as assert from 'assert'; | ||
import { readFileSync, writeFileSync } from 'fs'; | ||
import { join } from 'path'; | ||
import ts from 'typescript'; | ||
import { Document, DocumentManager } from '../../../../../src/lib/documents'; | ||
import { LSConfigManager } from '../../../../../src/ls-config'; | ||
import { LSAndTSDocResolver } from '../../../../../src/plugins'; | ||
import { FoldingRangeProviderImpl } from '../../../../../src/plugins/typescript/features/FoldingRangeProvider'; | ||
import { pathToUrl } from '../../../../../src/utils'; | ||
import { | ||
createJsonSnapshotFormatter, | ||
createSnapshotTester, | ||
updateSnapshotIfFailedOrEmpty | ||
} from '../../test-utils'; | ||
|
||
function setup(workspaceDir: string, filePath: string) { | ||
const docManager = new DocumentManager( | ||
(textDocument) => new Document(textDocument.uri, textDocument.text) | ||
); | ||
const configManager = new LSConfigManager(); | ||
configManager.updateClientCapabilities({ | ||
textDocument: { foldingRange: { lineFoldingOnly: true } } | ||
}); | ||
const lsAndTsDocResolver = new LSAndTSDocResolver( | ||
docManager, | ||
[pathToUrl(workspaceDir)], | ||
configManager | ||
); | ||
const plugin = new FoldingRangeProviderImpl(lsAndTsDocResolver, configManager); | ||
const document = docManager.openClientDocument(<any>{ | ||
uri: pathToUrl(filePath), | ||
text: ts.sys.readFile(filePath) || '' | ||
}); | ||
return { plugin, document, docManager, lsAndTsDocResolver }; | ||
} | ||
|
||
async function executeTest( | ||
inputFile: string, | ||
{ | ||
workspaceDir, | ||
dir | ||
}: { | ||
workspaceDir: string; | ||
dir: string; | ||
} | ||
) { | ||
const expected = 'expectedv2.json'; | ||
const { plugin, document } = setup(workspaceDir, inputFile); | ||
const folding = await plugin.getFoldingRanges(document); | ||
|
||
const expectedFile = join(dir, expected); | ||
if (process.argv.includes('--debug')) { | ||
writeFileSync(join(dir, 'debug.svelte'), appendFoldingAsComment()); | ||
} | ||
|
||
const snapshotFormatter = await createJsonSnapshotFormatter(dir); | ||
|
||
await updateSnapshotIfFailedOrEmpty({ | ||
assertion() { | ||
assert.deepStrictEqual( | ||
JSON.parse(JSON.stringify(folding)), | ||
JSON.parse(readFileSync(expectedFile, 'utf-8')) | ||
); | ||
}, | ||
expectedFile, | ||
getFileContent() { | ||
return snapshotFormatter(folding); | ||
}, | ||
rootDir: __dirname | ||
}); | ||
|
||
function appendFoldingAsComment() { | ||
if (!folding) { | ||
return document.getText(); | ||
} | ||
|
||
const offsetMap = new Map<number, string[]>(); | ||
const lineLength = document | ||
.getText() | ||
.split('\n') | ||
.map((line) => (line[line.length - 1] === '\r' ? line.length - 1 : line.length)); | ||
|
||
for (const fold of folding) { | ||
const startOffset = document.offsetAt({ | ||
line: fold.startLine, | ||
character: lineLength[fold.startLine] | ||
}); | ||
const endOffset = document.offsetAt({ | ||
line: fold.endLine, | ||
character: lineLength[fold.endLine] | ||
}); | ||
|
||
offsetMap.set(startOffset, (offsetMap.get(startOffset) ?? []).concat(`/*s*/`)); | ||
offsetMap.set(endOffset, (offsetMap.get(endOffset) ?? []).concat(`/*e*/`)); | ||
} | ||
|
||
const offsets = Array.from(offsetMap.keys()).sort((a, b) => a - b); | ||
const parts: string[] = []; | ||
|
||
for (let index = 0; index < offsets.length; index++) { | ||
const offset = offsets[index]; | ||
parts.push( | ||
document.getText().slice(offsets[index - 1], offset), | ||
...(offsetMap.get(offset) ?? []) | ||
); | ||
} | ||
|
||
parts.push(document.getText().slice(offsets[offsets.length - 1])); | ||
|
||
return parts.join(''); | ||
} | ||
} | ||
|
||
const executeTests = createSnapshotTester(executeTest); | ||
|
||
describe.only('FoldingRangeProvider', function () { | ||
executeTests({ | ||
dir: join(__dirname, 'fixtures'), | ||
workspaceDir: join(__dirname, 'fixtures'), | ||
context: this | ||
}); | ||
}); |