Skip to content

Commit ad5a116

Browse files
committed
#687 skip huge files
1 parent 5c84a83 commit ad5a116

File tree

5 files changed

+10
-2
lines changed

5 files changed

+10
-2
lines changed

changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
## 2.5.0
44
* `NEW` setting `Lua.runtime.pathStrict`
5+
* `NEW` skip huge files (>= 100 MB)
56
* `CHG` no longer asks to trust plugin in VSCode, because VSCode already provides the workspace trust feature
67

78
## 2.4.7

locale/en-us/script.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ MWS_WCONFIG_UPDATED = 'Workspace setting updated.'
6666
WORKSPACE_SKIP_LARGE_FILE = 'Too large file: {} skipped. The currently set size limit is: {} KB, and the file size is: {} KB.'
6767
WORKSPACE_LOADING = 'Loading workspace'
6868
WORKSPACE_DIAGNOSTIC = 'Diagnosing workspace'
69+
WORKSPACE_SKIP_HUGE_FILE = 'For performance reasons, the parsing of this file has been stopped: {}'
6970

7071
PARSER_CRASH = 'Parser crashed! Last words:{}'
7172
PARSER_UNKNOWN = 'Unknown syntax error...'

locale/zh-cn/script.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ MWS_WCONFIG_UPDATED = '工作区配置已更新。'
6666
WORKSPACE_SKIP_LARGE_FILE = '已跳过过大的文件:{}。当前设置的大小限制为:{} KB,该文件大小为:{} KB'
6767
WORKSPACE_LOADING = '正在加载工作目录'
6868
WORKSPACE_DIAGNOSTIC = '正在对工作目录进行诊断'
69+
WORKSPACE_SKIP_HUGE_FILE = '出于性能考虑,已停止对此文件解析:{}'
6970

7071
PARSER_CRASH = '语法解析崩溃了!遗言:{}'
7172
PARSER_UNKNOWN = '未知语法错误...'

script/files.lua

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ local guide = require 'parser.guide'
1111
local smerger = require 'string-merger'
1212
local progress = require "progress"
1313
local encoder = require 'encoder'
14+
local client = require 'client'
1415

1516
---@class files
1617
local m = {}
@@ -120,10 +121,14 @@ end
120121
--- 设置文件文本
121122
---@param uri uri
122123
---@param text string
123-
function m.setText(uri, text, isTrust, instance)
124+
function m.setText(uri, text, isTrust)
124125
if not text then
125126
return
126127
end
128+
if #text > 1024 * 1024 * 100 then
129+
client.showMessage('Warning', lang.script('WORKSPACE_SKIP_HUGE_FILE', uri))
130+
return
131+
end
127132
--log.debug('setText', uri)
128133
local create
129134
if not m.fileMap[uri] then

script/workspace/workspace.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ local function loadFileFactory(root, progressData, isLibrary)
246246
log.info('++++As library of:', root)
247247
files.setLibraryPath(uri, root)
248248
end
249-
files.setText(uri, text, false, true)
249+
files.setText(uri, text, false)
250250
else
251251
files.remove(uri)
252252
end

0 commit comments

Comments
 (0)