-
-
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.
chore: Update
volar-service-prettier
(#823)
* chore: Upgrade `volar-service-prettier` * bump * fix types * typo * Create thin-dragons-yell.md --------- Co-authored-by: Erika <[email protected]>
- Loading branch information
1 parent
390637f
commit f1447ef
Showing
6 changed files
with
156 additions
and
128 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
"astro-vscode": patch | ||
"@astrojs/check": patch | ||
"@astrojs/language-server": patch | ||
--- | ||
|
||
chore: Update `volar-service-prettier`. This is only an internal refactor and there should be no visible changes. |
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
111 changes: 58 additions & 53 deletions
111
packages/language-server/src/plugins/typescript/index.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 |
---|---|---|
@@ -1,71 +1,76 @@ | ||
import type { ServicePlugin, ServicePluginInstance } from '@volar/language-server'; | ||
import { create as createTypeScriptService } from 'volar-service-typescript'; | ||
import { create as createTypeScriptServices } from 'volar-service-typescript'; | ||
import { AstroVirtualCode } from '../../core/index.js'; | ||
import { enhancedProvideCodeActions, enhancedResolveCodeAction } from './codeActions.js'; | ||
import { enhancedProvideCompletionItems, enhancedResolveCompletionItem } from './completions.js'; | ||
import { enhancedProvideSemanticDiagnostics } from './diagnostics.js'; | ||
|
||
export const create = (ts: typeof import('typescript')): ServicePlugin => { | ||
const tsServicePlugin = createTypeScriptService(ts as typeof import('typescript')); | ||
return { | ||
...tsServicePlugin, | ||
create(context): ServicePluginInstance { | ||
const typeScriptPlugin = tsServicePlugin.create(context); | ||
export const create = (ts: typeof import('typescript')): ServicePlugin[] => { | ||
const tsServicePlugins = createTypeScriptServices(ts as typeof import('typescript'), {}); | ||
return tsServicePlugins.map<ServicePlugin>(plugin => { | ||
if (plugin.name === 'typescript-semantic') { | ||
return { | ||
...typeScriptPlugin, | ||
async provideCompletionItems(document, position, completionContext, token) { | ||
const originalCompletions = await typeScriptPlugin.provideCompletionItems!( | ||
document, | ||
position, | ||
completionContext, | ||
token | ||
); | ||
if (!originalCompletions) return null; | ||
...plugin, | ||
create(context): ServicePluginInstance { | ||
const typeScriptPlugin = plugin.create(context); | ||
return { | ||
...typeScriptPlugin, | ||
async provideCompletionItems(document, position, completionContext, token) { | ||
const originalCompletions = await typeScriptPlugin.provideCompletionItems!( | ||
document, | ||
position, | ||
completionContext, | ||
token | ||
); | ||
if (!originalCompletions) return null; | ||
|
||
return enhancedProvideCompletionItems(originalCompletions); | ||
}, | ||
async resolveCompletionItem(item, token) { | ||
const resolvedCompletionItem = await typeScriptPlugin.resolveCompletionItem!(item, token); | ||
if (!resolvedCompletionItem) return item; | ||
return enhancedProvideCompletionItems(originalCompletions); | ||
}, | ||
async resolveCompletionItem(item, token) { | ||
const resolvedCompletionItem = await typeScriptPlugin.resolveCompletionItem!(item, token); | ||
if (!resolvedCompletionItem) return item; | ||
|
||
return enhancedResolveCompletionItem(resolvedCompletionItem, context); | ||
}, | ||
async provideCodeActions(document, range, codeActionContext, token) { | ||
const originalCodeActions = await typeScriptPlugin.provideCodeActions!( | ||
document, | ||
range, | ||
codeActionContext, | ||
token | ||
); | ||
if (!originalCodeActions) return null; | ||
return enhancedResolveCompletionItem(resolvedCompletionItem, context); | ||
}, | ||
async provideCodeActions(document, range, codeActionContext, token) { | ||
const originalCodeActions = await typeScriptPlugin.provideCodeActions!( | ||
document, | ||
range, | ||
codeActionContext, | ||
token | ||
); | ||
if (!originalCodeActions) return null; | ||
|
||
return enhancedProvideCodeActions(originalCodeActions, context); | ||
}, | ||
async resolveCodeAction(codeAction, token) { | ||
const resolvedCodeAction = await typeScriptPlugin.resolveCodeAction!(codeAction, token); | ||
if (!resolvedCodeAction) return codeAction; | ||
return enhancedProvideCodeActions(originalCodeActions, context); | ||
}, | ||
async resolveCodeAction(codeAction, token) { | ||
const resolvedCodeAction = await typeScriptPlugin.resolveCodeAction!(codeAction, token); | ||
if (!resolvedCodeAction) return codeAction; | ||
|
||
return enhancedResolveCodeAction(resolvedCodeAction, context); | ||
}, | ||
async provideSemanticDiagnostics(document, token) { | ||
const [_, source] = context.documents.getVirtualCodeByUri(document.uri); | ||
const code = source?.generated?.code; | ||
let tsxLineCount = undefined; | ||
return enhancedResolveCodeAction(resolvedCodeAction, context); | ||
}, | ||
async provideSemanticDiagnostics(document, token) { | ||
const [_, source] = context.documents.getVirtualCodeByUri(document.uri); | ||
const code = source?.generated?.code; | ||
let tsxLineCount = undefined; | ||
|
||
if (code instanceof AstroVirtualCode) { | ||
// If we have compiler errors, our TSX isn't valid so don't bother showing TS errors | ||
if (code.hasCompilationErrors) return null; | ||
if (code instanceof AstroVirtualCode) { | ||
// If we have compiler errors, our TSX isn't valid so don't bother showing TS errors | ||
if (code.hasCompilationErrors) return null; | ||
|
||
// We'll use this to filter out diagnostics that are outside the mapped range of the TSX | ||
tsxLineCount = code.astroMeta.tsxRanges.body.end.line; | ||
} | ||
// We'll use this to filter out diagnostics that are outside the mapped range of the TSX | ||
tsxLineCount = code.astroMeta.tsxRanges.body.end.line; | ||
} | ||
|
||
const diagnostics = await typeScriptPlugin.provideSemanticDiagnostics!(document, token); | ||
if (!diagnostics) return null; | ||
const diagnostics = await typeScriptPlugin.provideSemanticDiagnostics!(document, token); | ||
if (!diagnostics) return null; | ||
|
||
return enhancedProvideSemanticDiagnostics(diagnostics, tsxLineCount); | ||
return enhancedProvideSemanticDiagnostics(diagnostics, tsxLineCount); | ||
}, | ||
}; | ||
}, | ||
}; | ||
}, | ||
}; | ||
} | ||
return plugin; | ||
}); | ||
}; |
Oops, something went wrong.