Skip to content

Commit 4a2203d

Browse files
committed
2 parents 3f620ce + 38adf62 commit 4a2203d

File tree

8 files changed

+49
-14
lines changed

8 files changed

+49
-14
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
local files = require("files")
2+
local codeFormat = require "code_format"
3+
local converter = require("proto.converter")
4+
local log = require("log")
5+
local config = require("config")
6+
7+
8+
---@async
9+
return function(uri, callback)
10+
local text = files.getText(uri)
11+
if not text then
12+
return
13+
end
14+
15+
local status, diagnosticInfos = codeFormat.diagnose_file(uri, text)
16+
17+
if not status then
18+
if diagnosticInfos ~= nil then
19+
log.error(diagnosticInfos)
20+
end
21+
22+
return
23+
end
24+
25+
if diagnosticInfos then
26+
for _, diagnosticInfo in pairs(diagnosticInfos) do
27+
callback {
28+
start = converter.unpackPosition(uri, diagnosticInfo.range.start),
29+
finish = converter.unpackPosition(uri, diagnosticInfo.range["end"]),
30+
message = diagnosticInfo.message
31+
}
32+
end
33+
end
34+
end

script/core/formatting.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
local code_format = require "code_format"
1+
local codeFormat = require("code_format")
22
local files = require("files")
33
local log = require("log")
44

55
return function(uri)
66
local text = files.getText(uri)
77
local ast = files.getState(uri)
8-
local status, formattedText = code_format.format(uri, text)
8+
local status, formattedText = codeFormat.format(uri, text)
99

1010
if not status then
1111
if formattedText ~= nil then

script/core/rangeformatting.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
local code_format = require "code_format"
1+
local codeFormat = require("code_format")
22
local files = require("files")
33
local log = require("log")
44
local converter = require("proto.converter")
55

66
return function(uri, range)
77
local text = files.getText(uri)
8-
local status, formattedText, startLine, endLine = code_format.range_format(
8+
local status, formattedText, startLine, endLine = codeFormat.range_format(
99
uri, text, range.start.line, range["end"].line)
1010

1111
if not status then

script/core/type-formatting.lua

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ local function checkSplitOneLine(results, uri, position, ch)
4646
if ch ~= '\n' then
4747
return
4848
end
49+
4950
local fPosition, fSymbol = findForward(uri, position, 'end', '}')
5051
if not fPosition then
5152
return
@@ -77,7 +78,7 @@ local function checkSplitOneLine(results, uri, position, ch)
7778
end
7879

7980
return function (uri, position, ch)
80-
local ast = files.getState(uri)
81+
local ast = files.getState(uri)
8182
if not ast then
8283
return nil
8384
end

script/proto/define.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ m.DiagnosticDefaultSeverity = {
5858
['doc-field-no-class'] = 'Warning',
5959
['duplicate-doc-field'] = 'Warning',
6060
['unknown-diag-code'] = 'Waiting',
61+
['codestyle-check'] = "Warning",
6162
}
6263

6364
---@alias DiagnosticDefaultNeededFileStatus

script/provider/capability.lua

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,6 @@ function m.getIniter()
114114
},
115115
documentFormattingProvider = true,
116116
documentRangeFormattingProvider = true
117-
--documentOnTypeFormattingProvider = {
118-
-- firstTriggerCharacter = '}',
119-
--},
120117
}
121118

122119
--testFileEvents()

script/provider/provider.lua

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,9 @@ m.register 'initialize' {
103103

104104
if params.initializationOptions then
105105
if params.initializationOptions.editorConfigFiles then
106-
local code_format = require "code_format"
106+
local codeFormat = require "code_format"
107107
for _, config in pairs(params.initializationOptions.editorConfigFiles) do
108-
local status, err = code_format.update_config(1, config.workspace, config.path)
108+
local status, err = codeFormat.update_config(1, config.workspace, config.path)
109109

110110
if not status and err ~= nil then
111111
log.error(err)
@@ -930,7 +930,7 @@ m.register 'textDocument/formatting' {
930930
function(params)
931931
local uri = files.getRealUri(params.textDocument.uri)
932932
workspace.awaitReady(uri)
933-
local _<close> = progress.create(workspace.getScope(uri), lang.script.WINDOW_PROCESSING_TYPE_FORMATTING, 0.5)
933+
local _ <close> = progress.create(workspace.getScope(uri), lang.script.WINDOW_PROCESSING_TYPE_FORMATTING, 0.5)
934934

935935
if not files.exists(uri) then
936936
return nil
@@ -960,7 +960,7 @@ m.register 'textDocument/rangeFormatting' {
960960
function(params)
961961
local uri = files.getRealUri(params.textDocument.uri)
962962
workspace.awaitReady(uri)
963-
local _<close> = progress.create(workspace.getScope(uri), lang.script.WINDOW_PROCESSING_TYPE_FORMATTING, 0.5)
963+
local _ <close> = progress.create(workspace.getScope(uri), lang.script.WINDOW_PROCESSING_TYPE_FORMATTING, 0.5)
964964

965965
if not files.exists(uri) then
966966
return nil
@@ -988,8 +988,8 @@ m.register 'config/editorconfig/update' {
988988
abortByFileUpdate = true,
989989
---@async
990990
function(params)
991-
local code_format = require "code_format"
992-
local status, err = code_format.update_config(params.type, params.source.workspace, params.source.path)
991+
local codeFormat = require "code_format"
992+
local status, err = codeFormat.update_config(params.type, params.source.workspace, params.source.path)
993993

994994
if not status and err ~= nil then
995995
log.error(err)

test/crossfile/diagnostic.lua

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@ local config = require 'config'
55
local platform = require 'bee.platform'
66
local catch = require 'catch'
77

8+
89
config.get(nil, 'Lua.diagnostics.neededFileStatus')['deprecated'] = 'Any'
910
config.get(nil, 'Lua.diagnostics.neededFileStatus')['type-check'] = 'Any'
11+
config.get(nil, 'Lua.diagnostics.neededFileStatus')['codestyle-check'] = 'None'
1012

1113
rawset(_G, 'TEST', true)
1214

0 commit comments

Comments
 (0)