diff options
Diffstat (limited to 'server/src/method/textDocument')
-rw-r--r-- | server/src/method/textDocument/definition.lua | 1 | ||||
-rw-r--r-- | server/src/method/textDocument/hover.lua | 1 | ||||
-rw-r--r-- | server/src/method/textDocument/implementation.lua | 1 | ||||
-rw-r--r-- | server/src/method/textDocument/publishDiagnostics.lua | 74 | ||||
-rw-r--r-- | server/src/method/textDocument/references.lua | 1 | ||||
-rw-r--r-- | server/src/method/textDocument/rename.lua | 1 |
6 files changed, 74 insertions, 5 deletions
diff --git a/server/src/method/textDocument/definition.lua b/server/src/method/textDocument/definition.lua index a0a25f46..4d3d861e 100644 --- a/server/src/method/textDocument/definition.lua +++ b/server/src/method/textDocument/definition.lua @@ -1,4 +1,3 @@ -local parser = require 'parser' local matcher = require 'matcher' return function (lsp, params) diff --git a/server/src/method/textDocument/hover.lua b/server/src/method/textDocument/hover.lua index 2fd7aaec..5cb581a3 100644 --- a/server/src/method/textDocument/hover.lua +++ b/server/src/method/textDocument/hover.lua @@ -1,4 +1,3 @@ -local parser = require 'parser' local matcher = require 'matcher' return function (lsp, params) diff --git a/server/src/method/textDocument/implementation.lua b/server/src/method/textDocument/implementation.lua index c0a37830..aef9f1a0 100644 --- a/server/src/method/textDocument/implementation.lua +++ b/server/src/method/textDocument/implementation.lua @@ -1,4 +1,3 @@ -local parser = require 'parser' local matcher = require 'matcher' return function (lsp, params) diff --git a/server/src/method/textDocument/publishDiagnostics.lua b/server/src/method/textDocument/publishDiagnostics.lua new file mode 100644 index 00000000..5f3d1d28 --- /dev/null +++ b/server/src/method/textDocument/publishDiagnostics.lua @@ -0,0 +1,74 @@ +local matcher = require 'matcher' + +local DiagnosticSeverity = { + Error = 1, + Warning = 2, + Information = 3, + Hint = 4, +} + +--[[ +/** + * Represents a related message and source code location for a diagnostic. This should be + * used to point to code locations that cause or related to a diagnostics, e.g when duplicating + * a symbol in a scope. + */ +export interface DiagnosticRelatedInformation { + /** + * The location of this related diagnostic information. + */ + location: Location; + + /** + * The message of this related diagnostic information. + */ + message: string; +} +]]-- + +local function getRange(start, finish, lines) + local start_row, start_col = lines:rowcol(start, 'utf8') + local finish_row, finish_col = lines:rowcol(finish, 'utf8') + return { + start = { + line = start_row - 1, + character = start_col - 1, + }, + ['end'] = { + line = finish_row - 1, + -- 这里不用-1,因为前端期待的是匹配完成后的位置 + character = finish_col, + }, + } +end + +local function createInfo(data, lines) + local diagnostic = { + source = 'Lsp', + range = getRange(data.start, data.finish, lines), + severity = DiagnosticSeverity[data.level], + code = data.code, + message = data.message, + } + return diagnostic +end + +return function (lsp, params) + local results = params.results + local ast = params.ast + local lines = params.lines + + local datas = matcher.diagnostics(ast, results, lines) + + if not datas then + -- 返回空表以清空之前的结果 + return {} + end + + local diagnostics = {} + for i, data in ipairs(datas) do + diagnostics[i] = createInfo(data, lines) + end + + return diagnostics +end diff --git a/server/src/method/textDocument/references.lua b/server/src/method/textDocument/references.lua index b816e732..4b17700e 100644 --- a/server/src/method/textDocument/references.lua +++ b/server/src/method/textDocument/references.lua @@ -1,4 +1,3 @@ -local parser = require 'parser' local matcher = require 'matcher' return function (lsp, params) diff --git a/server/src/method/textDocument/rename.lua b/server/src/method/textDocument/rename.lua index f8d46409..bfb5cbba 100644 --- a/server/src/method/textDocument/rename.lua +++ b/server/src/method/textDocument/rename.lua @@ -1,4 +1,3 @@ -local parser = require 'parser' local matcher = require 'matcher' return function (lsp, params) |