Skip to content

Commit

Permalink
feat: add setting volar.vueserver.maxFileSize
Browse files Browse the repository at this point in the history
close #2186
  • Loading branch information
johnsoncodehk committed Dec 18, 2022
1 parent 42d0920 commit d247bb7
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 0 deletions.
5 changes: 5 additions & 0 deletions extensions/vscode-vue-language-features/package.json
Expand Up @@ -291,6 +291,11 @@
"default": "off",
"description": "Traces the communication between VS Code and the language server."
},
"volar.vueserver.maxFileSize": {
"type": "number",
"default": 20971520,
"description": "Maximum file size for Vue Server to load. (default: 20MB)"
},
"volar.vueserver.petiteVue.processHtmlFile": {
"type": "boolean",
"default": false
Expand Down
2 changes: 2 additions & 0 deletions extensions/vscode-vue-language-features/src/common.ts
Expand Up @@ -167,6 +167,7 @@ async function doActivate(context: vscode.ExtensionContext, createLc: CreateLang
|| e.affectsConfiguration('volar.vueserver.petiteVue.processHtmlFile')
|| e.affectsConfiguration('volar.vueserver.vitePress.processMdFile')
|| e.affectsConfiguration('volar.vueserver.additionalExtensions')
|| e.affectsConfiguration('volar.vueserver.maxFileSize')
) {
requestReloadVscode();
}
Expand Down Expand Up @@ -326,6 +327,7 @@ function getInitializationOptions(
customBlockSchemaUrls: vscode.workspace.getConfiguration('volar').get<Record<string, string>>('vueserver.json.customBlockSchemaUrls')
},
additionalExtensions: additionalExtensions(),
maxFileSize: vscode.workspace.getConfiguration('volar').get<number>('vueserver.maxFileSize'),
};
return initializationOptions;
}
1 change: 1 addition & 0 deletions packages/language-server/src/types.ts
Expand Up @@ -118,4 +118,5 @@ export interface LanguageServerInitializationOptions {
* Enable this option to make language server setup server capabilities based on client capabilities to support multiple servers.
*/
respectClientCapabilities?: boolean;
maxFileSize?: number;
}
7 changes: 7 additions & 0 deletions packages/language-server/src/utils/project.ts
Expand Up @@ -219,6 +219,13 @@ export async function createProject(
}

if (sys.fileExists(fileName)) {
if (serverOptions.maxFileSize) {
const fileSize = sys.getFileSize?.(fileName);
if (fileSize !== undefined && fileSize > serverOptions.maxFileSize) {
console.warn(`IGNORING "${fileName}" because it is too large (${fileSize}bytes > ${serverOptions.maxFileSize}bytes)`);
return ts.ScriptSnapshot.fromString('');
}
}
const text = sys.readFile(fileName, 'utf8');
if (text !== undefined) {
const snapshot = ts.ScriptSnapshot.fromString(text);
Expand Down

0 comments on commit d247bb7

Please sign in to comment.