-
Notifications
You must be signed in to change notification settings - Fork 51
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
0551a33
commit 9ef35df
Showing
1 changed file
with
238 additions
and
0 deletions.
There are no files selected for viewing
238 changes: 238 additions & 0 deletions
238
packages/core/__tests__/language-server/folding-ranges.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,238 @@ | ||
import { Project } from 'glint-monorepo-test-utils'; | ||
import { describe, beforeEach, afterEach, test, expect } from 'vitest'; | ||
import { stripIndent } from 'common-tags'; | ||
|
||
describe('Language Server: Folding Ranges', () => { | ||
let project!: Project; | ||
|
||
beforeEach(async () => { | ||
project = await Project.create(); | ||
}); | ||
|
||
afterEach(async () => { | ||
await project.destroy(); | ||
}); | ||
|
||
test('function', () => { | ||
project.write({ | ||
'example.ts': stripIndent` | ||
function foo() { | ||
return 'bar'; | ||
} | ||
`, | ||
}); | ||
|
||
let server = project.startLanguageServer(); | ||
let folds = server.getFoldingRanges(project.fileURI('example.ts')); | ||
|
||
expect(folds).toEqual([ | ||
{ | ||
startLine: 0, | ||
endLine: 1, | ||
kind: undefined, | ||
}, | ||
]); | ||
}); | ||
|
||
test('nested function', () => { | ||
project.write({ | ||
'example.ts': stripIndent` | ||
function topLevel() { | ||
function nested() { | ||
return 'bar'; | ||
} | ||
return nested(); | ||
} | ||
`, | ||
}); | ||
|
||
let server = project.startLanguageServer(); | ||
let folds = server.getFoldingRanges(project.fileURI('example.ts')); | ||
|
||
expect(folds).toEqual([ | ||
{ | ||
startLine: 0, | ||
endLine: 6, | ||
kind: undefined, | ||
}, | ||
{ | ||
startLine: 2, | ||
endLine: 3, | ||
kind: undefined, | ||
}, | ||
]); | ||
}); | ||
|
||
test('imports', () => { | ||
project.write({ | ||
'example.ts': stripIndent` | ||
import Component, { hbs } from '@glimmerx/component'; | ||
import foo from 'bar'; | ||
import { baz } from 'qux'; | ||
export default { foo, baz, Component }; | ||
`, | ||
}); | ||
|
||
let server = project.startLanguageServer(); | ||
let folds = server.getFoldingRanges(project.fileURI('example.ts')); | ||
|
||
expect(folds).toEqual([ | ||
{ | ||
startLine: 0, | ||
endLine: 2, | ||
kind: 'imports', | ||
}, | ||
]); | ||
}); | ||
|
||
test('comments', () => { | ||
project.write({ | ||
'example.ts': stripIndent` | ||
// This is | ||
// a | ||
// multiline | ||
// comment | ||
const foo = 'bar'; | ||
`, | ||
}); | ||
|
||
let server = project.startLanguageServer(); | ||
let folds = server.getFoldingRanges(project.fileURI('example.ts')); | ||
|
||
expect(folds).toEqual([ | ||
{ | ||
startLine: 0, | ||
endLine: 3, | ||
kind: 'comment', | ||
}, | ||
]); | ||
}); | ||
|
||
test('region', () => { | ||
project.write({ | ||
'example.ts': stripIndent` | ||
const foo = 'bar'; | ||
// #region | ||
const bar = 'baz'; | ||
// #endregion | ||
export default { foo, bar }; | ||
`, | ||
}); | ||
|
||
let server = project.startLanguageServer(); | ||
let folds = server.getFoldingRanges(project.fileURI('example.ts')); | ||
|
||
expect(folds).toEqual([ | ||
{ | ||
startLine: 2, | ||
endLine: 6, | ||
kind: 'region', | ||
}, | ||
]); | ||
}); | ||
|
||
test('simple component', () => { | ||
project.write({ | ||
'example.ts': stripIndent` | ||
import Component, { hbs } from '@glimmerx/component'; | ||
import { tracked } from '@glimmer/tracking'; | ||
export interface EmberComponentArgs { | ||
message: string; | ||
} | ||
export interface EmberComponentSignature { | ||
Element: HTMLDivElement; | ||
Args: EmberComponentArgs; | ||
} | ||
/** | ||
* A simple component that renders a message. | ||
*/ | ||
export default class Greeting extends Component<EmberComponentSignature> { | ||
@tracked message = this.args.message; | ||
get capitalizedMessage() { | ||
return this.message.toUpperCase(); | ||
} | ||
} | ||
declare module '@glint/environment-ember-loose/registry' { | ||
export default interface Registry { | ||
EmberComponent: typeof EmberComponent; | ||
'ember-component': typeof EmberComponent; | ||
} | ||
} | ||
`, | ||
}); | ||
|
||
let server = project.startLanguageServer(); | ||
let folds = server.getFoldingRanges(project.fileURI('example.ts')); | ||
|
||
expect(folds).toEqual([ | ||
// Imports | ||
{ | ||
startLine: 0, | ||
endLine: 1, | ||
kind: 'imports', | ||
}, | ||
|
||
// EmberComponentArgs | ||
{ | ||
startLine: 3, | ||
endLine: 4, | ||
kind: undefined, | ||
}, | ||
|
||
// EmberComponentSignature | ||
{ | ||
startLine: 7, | ||
endLine: 9, | ||
kind: undefined, | ||
}, | ||
|
||
// Code Comment | ||
{ | ||
startLine: 12, | ||
endLine: 14, | ||
kind: 'comment', | ||
}, | ||
|
||
// Greeting Component | ||
{ | ||
startLine: 15, | ||
endLine: 20, | ||
kind: undefined, | ||
}, | ||
|
||
// capitalizedMessage | ||
{ | ||
startLine: 18, | ||
endLine: 19, | ||
kind: undefined, | ||
}, | ||
|
||
// declare module | ||
{ | ||
startLine: 23, | ||
endLine: 27, | ||
kind: undefined, | ||
}, | ||
|
||
// interface Registry | ||
{ | ||
startLine: 24, | ||
endLine: 26, | ||
kind: undefined, | ||
}, | ||
]); | ||
}); | ||
}); |