-
Notifications
You must be signed in to change notification settings - Fork 54
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
adf49dd
commit 943d596
Showing
7 changed files
with
378 additions
and
26 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
import { Project } from 'glint-monorepo-test-utils'; | ||
import { describe, beforeEach, afterEach, test, expect } from 'vitest'; | ||
import { Position, Range } from 'vscode-languageserver'; | ||
|
||
describe('Language Server: iInlays', () => { | ||
let project!: Project; | ||
|
||
beforeEach(async () => { | ||
project = await Project.create(); | ||
}); | ||
|
||
afterEach(async () => { | ||
await project.destroy(); | ||
}); | ||
|
||
test('it provides inlays for return types when preference is set', async () => { | ||
project.setGlintConfig({ environment: 'ember-template-imports' }); | ||
let content = 'const bar = () => true;'; | ||
project.write('foo.gts', content); | ||
let server = project.startLanguageServer(); | ||
|
||
const inlays = server.getInlayHints( | ||
{ | ||
textDocument: { | ||
uri: project.fileURI('foo.gts'), | ||
}, | ||
range: Range.create(Position.create(0, 0), Position.create(0, content.length)), | ||
}, | ||
{ | ||
includeInlayFunctionLikeReturnTypeHints: true, | ||
} | ||
); | ||
|
||
expect(inlays.length).toBe(1); | ||
expect(inlays[0].kind).toBe(1); | ||
expect(inlays[0].label).toBe(': boolean'); | ||
}); | ||
|
||
test('it provides inlays for variable types when preference is set', async () => { | ||
project.setGlintConfig({ environment: 'ember-template-imports' }); | ||
let content = 'const bar = globalThis.thing ?? null;'; | ||
project.write('foo.gts', content); | ||
let server = project.startLanguageServer(); | ||
|
||
const inlays = server.getInlayHints( | ||
{ | ||
textDocument: { | ||
uri: project.fileURI('foo.gts'), | ||
}, | ||
range: Range.create(Position.create(0, 0), Position.create(0, content.length)), | ||
}, | ||
{ | ||
includeInlayVariableTypeHints: true, | ||
} | ||
); | ||
|
||
expect(inlays.length).toBe(1); | ||
expect(inlays[0].kind).toBe(1); | ||
expect(inlays[0].label).toBe(': any'); | ||
}); | ||
|
||
test('it provides inlays for property types when preference is set', async () => { | ||
project.setGlintConfig({ environment: 'ember-template-imports' }); | ||
let content = 'class Foo { date = Date.now() }'; | ||
project.write('foo.gts', content); | ||
let server = project.startLanguageServer(); | ||
|
||
const inlays = server.getInlayHints( | ||
{ | ||
textDocument: { | ||
uri: project.fileURI('foo.gts'), | ||
}, | ||
range: Range.create(Position.create(0, 0), Position.create(0, content.length)), | ||
}, | ||
{ | ||
includeInlayPropertyDeclarationTypeHints: true, | ||
} | ||
); | ||
|
||
expect(inlays.length).toBe(1); | ||
expect(inlays[0].kind).toBe(1); | ||
expect(inlays[0].label).toBe(': number'); | ||
}); | ||
}); |
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
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,64 @@ | ||
import { type WorkspaceConfiguration, window } from 'vscode'; | ||
import type * as ts from 'typescript/lib/tsserverlibrary'; | ||
|
||
// vscode does not hold formatting config with the same interface as typescript | ||
// the following maps the vscode formatting options into what typescript expects | ||
// This is heavily borrowed from how the TypeScript works in vscode | ||
// https://github.com/microsoft/vscode/blob/c04c0b43470c3c743468a5e5e51f036123503452/extensions/typescript-language-features/src/languageFeatures/fileConfigurationManager.ts#L133 | ||
export function intoFormatting( | ||
config: WorkspaceConfiguration | ||
): ts.server.protocol.FormatCodeSettings { | ||
let editorOptions = window.activeTextEditor?.options; | ||
let tabSize = typeof editorOptions?.tabSize === 'string' ? undefined : editorOptions?.tabSize; | ||
let insertSpaces = | ||
typeof editorOptions?.insertSpaces === 'string' ? undefined : editorOptions?.insertSpaces; | ||
|
||
return { | ||
tabSize, | ||
indentSize: tabSize, | ||
convertTabsToSpaces: insertSpaces, | ||
// We can use \n here since the editor normalizes later on to its line endings. | ||
newLineCharacter: '\n', | ||
insertSpaceAfterCommaDelimiter: config.get<boolean>('insertSpaceAfterCommaDelimiter'), | ||
insertSpaceAfterConstructor: config.get<boolean>('insertSpaceAfterConstructor'), | ||
insertSpaceAfterSemicolonInForStatements: config.get<boolean>( | ||
'insertSpaceAfterSemicolonInForStatements' | ||
), | ||
insertSpaceBeforeAndAfterBinaryOperators: config.get<boolean>( | ||
'insertSpaceBeforeAndAfterBinaryOperators' | ||
), | ||
insertSpaceAfterKeywordsInControlFlowStatements: config.get<boolean>( | ||
'insertSpaceAfterKeywordsInControlFlowStatements' | ||
), | ||
insertSpaceAfterFunctionKeywordForAnonymousFunctions: config.get<boolean>( | ||
'insertSpaceAfterFunctionKeywordForAnonymousFunctions' | ||
), | ||
insertSpaceBeforeFunctionParenthesis: config.get<boolean>( | ||
'insertSpaceBeforeFunctionParenthesis' | ||
), | ||
insertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis: config.get<boolean>( | ||
'insertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis' | ||
), | ||
insertSpaceAfterOpeningAndBeforeClosingNonemptyBrackets: config.get<boolean>( | ||
'insertSpaceAfterOpeningAndBeforeClosingNonemptyBrackets' | ||
), | ||
insertSpaceAfterOpeningAndBeforeClosingNonemptyBraces: config.get<boolean>( | ||
'insertSpaceAfterOpeningAndBeforeClosingNonemptyBraces' | ||
), | ||
insertSpaceAfterOpeningAndBeforeClosingEmptyBraces: config.get<boolean>( | ||
'insertSpaceAfterOpeningAndBeforeClosingEmptyBraces' | ||
), | ||
insertSpaceAfterOpeningAndBeforeClosingTemplateStringBraces: config.get<boolean>( | ||
'insertSpaceAfterOpeningAndBeforeClosingTemplateStringBraces' | ||
), | ||
insertSpaceAfterOpeningAndBeforeClosingJsxExpressionBraces: config.get<boolean>( | ||
'insertSpaceAfterOpeningAndBeforeClosingJsxExpressionBraces' | ||
), | ||
insertSpaceAfterTypeAssertion: config.get<boolean>('insertSpaceAfterTypeAssertion'), | ||
placeOpenBraceOnNewLineForFunctions: config.get<boolean>('placeOpenBraceOnNewLineForFunctions'), | ||
placeOpenBraceOnNewLineForControlBlocks: config.get<boolean>( | ||
'placeOpenBraceOnNewLineForControlBlocks' | ||
), | ||
semicolons: config.get<ts.server.protocol.SemicolonPreference>('semicolons'), | ||
}; | ||
} |
Oops, something went wrong.