Skip to content

Commit 3c7ab17

Browse files
hf02href
andauthored
Add option to disable the auto import cache (#1038)
* disable auto import cache * add option to disable the auto import cache * changeset --------- Co-authored-by: href <href2@lizardmail.me>
1 parent ce2e1d2 commit 3c7ab17

File tree

6 files changed

+31
-4
lines changed

6 files changed

+31
-4
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'@astrojs/language-server': minor
3+
'astro-vscode': minor
4+
---
5+
6+
Allow disabling the Auto Import Cache. The cache can cause an issue where new files are not able to be automatically imported using autocomplete. Workaround for #1038.

‎packages/language-server/src/languageServerPlugin.ts‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import {
22
type Connection,
3+
InitializeParams,
34
type LanguagePlugin,
45
MessageType,
56
ShowMessageNotification,
@@ -38,12 +39,15 @@ export function getLanguageServicePlugins(
3839
connection: Connection,
3940
ts: typeof import('typescript'),
4041
collectionConfig: CollectionConfig,
42+
initializeParams?: InitializeParams
4143
) {
4244
const LanguageServicePlugins = [
4345
createHtmlService(),
4446
createCssService(),
4547
createEmmetService(),
46-
...createTypeScriptServices(ts),
48+
...createTypeScriptServices(ts, {
49+
disableAutoImportCache: initializeParams?.initializationOptions?.disableAutoImportCache,
50+
}),
4751
createTypeScriptTwoSlashService(ts),
4852
createTypescriptAddonsService(),
4953
createAstroService(ts),

‎packages/language-server/src/nodeServer.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ connection.onInitialize((params) => {
110110
},
111111
};
112112
}),
113-
getLanguageServicePlugins(connection, typescript, collectionConfig),
113+
getLanguageServicePlugins(connection, typescript, collectionConfig, params),
114114
);
115115
});
116116

‎packages/language-server/src/plugins/typescript/index.ts‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,13 @@ import { enhancedProvideCodeActions, enhancedResolveCodeAction } from './codeAct
66
import { enhancedProvideCompletionItems, enhancedResolveCompletionItem } from './completions.js';
77
import { enhancedProvideSemanticDiagnostics } from './diagnostics.js';
88

9-
export const create = (ts: typeof import('typescript')): LanguageServicePlugin[] => {
10-
const tsServicePlugins = createTypeScriptServices(ts as typeof import('typescript'), {});
9+
export const create = (ts: typeof import('typescript'), options?: {
10+
disableAutoImportCache: boolean | undefined;
11+
}): LanguageServicePlugin[] => {
12+
const tsServicePlugins = createTypeScriptServices(ts as typeof import('typescript'), {
13+
disableAutoImportCache: options?.disableAutoImportCache,
14+
});
15+
1116
return tsServicePlugins.map<LanguageServicePlugin>((plugin) => {
1217
if (plugin.name === 'typescript-semantic') {
1318
return {

‎packages/vscode/package.json‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,12 @@
148148
"default": false,
149149
"description": "Enable experimental support for content collection intellisense inside Markdown, MDX and Markdoc. Note that this require also enabling the feature in your Astro config (experimental.contentCollectionIntellisense) (Astro 4.14+)"
150150
},
151+
"astro.auto-import-cache.enabled": {
152+
"scope": "resource",
153+
"type": "boolean",
154+
"default": true,
155+
"markdownDescription": "Enable the auto import cache. Yields a faster intellisense when automatically importing a file, but can cause issues with new files not being detected. Change is applied on restart. See [#1035](https://github.com/withastro/language-tools/issues/1035)."
156+
},
151157
"astro.updateImportsOnFileMove.enabled": {
152158
"scope": "resource",
153159
"type": "boolean",

‎packages/vscode/src/client.ts‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,17 @@ export async function activate(context: vscode.ExtensionContext): Promise<LabsIn
6666
const hasContentIntellisense = vscode.workspace
6767
.getConfiguration('astro')
6868
.get('content-intellisense');
69+
70+
const shouldDisableAutoImportCache = vscode.workspace
71+
.getConfiguration('astro')
72+
.get('auto-import-cache.enabled') === false;
73+
6974
const initializationOptions = {
7075
typescript: {
7176
tsdk: (await getTsdk(context))!.tsdk,
7277
},
7378
contentIntellisense: hasContentIntellisense,
79+
disableAutoImportCache: shouldDisableAutoImportCache,
7480
} satisfies InitOptions;
7581

7682
const clientOptions = {

0 commit comments

Comments
 (0)