Skip to content

Commit 5eef995

Browse files
committed
格式化支持简单非标准符号
1 parent 6866310 commit 5eef995

File tree

3 files changed

+32
-7
lines changed

3 files changed

+32
-7
lines changed

3rd/EmmyLuaCodeStyle

Submodule EmmyLuaCodeStyle updated 86 files

script/provider/formatting.lua

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ local updateType = {
1919
Deleted = 3,
2020
}
2121

22-
fw.event(function (ev, path)
22+
fw.event(function(ev, path)
2323
if util.stringEndWith(path, '.editorconfig') then
2424
for uri, fsPath in pairs(loadedUris) do
2525
loadedUris[uri] = nil
@@ -36,11 +36,6 @@ fw.event(function (ev, path)
3636
end
3737
end)
3838

39-
config.watch(function (uri, key, value)
40-
if key == "Lua.format.defaultConfig" then
41-
codeFormat.set_default_config(value)
42-
end
43-
end)
4439

4540
local m = {}
4641

@@ -51,6 +46,7 @@ function m.updateConfig(uri)
5146
if not m.loadedDefaultConfig then
5247
m.loadedDefaultConfig = true
5348
codeFormat.set_default_config(config.get(uri, 'Lua.format.defaultConfig'))
49+
m.updateNonStandardSymbols(config.get(nil, 'Lua.runtime.nonstandardSymbol'))
5450
end
5551

5652
local currentUri = uri
@@ -83,4 +79,31 @@ function m.updateConfig(uri)
8379
end
8480
end
8581

82+
---@param symbols? string[]
83+
function m.updateNonStandardSymbols(symbols)
84+
if symbols == nil then
85+
return
86+
end
87+
88+
local eqTokens = {}
89+
for token in pairs(symbols) do
90+
if token:find("=") and token ~= "!=" then
91+
table.insert(eqTokens, token)
92+
end
93+
end
94+
95+
if #eqTokens ~= 0 then
96+
local result = codeFormat.set_nonstandard_symbol('=', eqTokens)
97+
log.info(result)
98+
end
99+
end
100+
101+
config.watch(function(uri, key, value)
102+
if key == "Lua.format.defaultConfig" then
103+
codeFormat.set_default_config(value)
104+
elseif key == "Lua.runtime.nonstandardSymbol" then
105+
m.updateNonStandardSymbols(value)
106+
end
107+
end)
108+
86109
return m

script/provider/spell.lua

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ end
66
local fs = require 'bee.filesystem'
77
local config = require 'config'
88
local diagnostics = require 'provider.diagnostic'
9+
local pformatting = require 'provider.formatting'
910

1011
local m = {}
1112

@@ -45,6 +46,7 @@ function m.initDictionary()
4546

4647
m.loadDictionaryFromFile(basicDictionary:string())
4748
m.loadDictionaryFromFile(luaDictionary:string())
49+
pformatting.updateNonStandardSymbols(config.get(nil, "Lua.runtime.nonstandardSymbol"))
4850
end
4951

5052
config.watch(function (uri, key, value, oldValue)

0 commit comments

Comments
 (0)