MCPcopy Create free account
hub / github.com/CppCXY/EmmyLuaCodeStyle / Diagnostic

Method Diagnostic

CodeFormatServer/src/Service/DiagnosticService.cpp:12–86  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

10}
11
12std::vector<lsp::Diagnostic>
13DiagnosticService::Diagnostic(std::size_t fileId,
14 const LuaSyntaxTree &luaSyntaxTree, LuaStyle &luaStyle) {
15 LuaDiagnosticStyle &diagnosticStyle = _owner->GetService<ConfigService>()->GetDiagnosticStyle();
16
17 DiagnosticBuilder d(luaStyle, diagnosticStyle);
18
19 d.CodeStyleCheck(luaSyntaxTree);
20 d.SpellCheck(luaSyntaxTree, *_spellChecker);
21 d.NameStyleCheck(luaSyntaxTree);
22
23 auto results = d.GetDiagnosticResults(luaSyntaxTree);
24 std::vector<lsp::Diagnostic> diagnostics;
25 auto &vfs = _owner->GetVFS();
26 auto vFile = vfs.GetVirtualFile(fileId);
27 auto lineIndex = vFile.GetLineIndex(vfs);
28 if (!lineIndex) {
29 return diagnostics;
30 }
31
32 for (auto &result: results) {
33 auto &diag = diagnostics.emplace_back();
34 diag.message = result.Message;
35 auto startLC = lineIndex->GetLineCol(result.Range.StartOffset);
36 auto endLC = lineIndex->GetLineCol(result.Range.GetEndOffset());
37 diag.range = lsp::Range(
38 lsp::Position(startLC.Line, startLC.Col),
39 lsp::Position(endLC.Line, endLC.Col + 1));
40 diag.data = result.Data;
41
42 diag.source = "EmmyLua";
43 diag.code = _owner->GetService<CodeActionService>()->GetCode(result.Type);
44 switch (result.Type) {
45 case DiagnosticType::Indent: {
46 diag.severity = lsp::DiagnosticSeverity::Warning;
47 break;
48 }
49 case DiagnosticType::Space: {
50 diag.severity = lsp::DiagnosticSeverity::Warning;
51 break;
52 }
53 case DiagnosticType::StringQuote: {
54 diag.severity = lsp::DiagnosticSeverity::Warning;
55 break;
56 }
57 case DiagnosticType::EndWithNewLine: {
58 diag.severity = lsp::DiagnosticSeverity::Warning;
59 break;
60 }
61 case DiagnosticType::Align: {
62 diag.severity = lsp::DiagnosticSeverity::Warning;
63 break;
64 }
65 case DiagnosticType::Semicolon: {
66 diag.severity = lsp::DiagnosticSeverity::Warning;
67 break;
68 }
69 case DiagnosticType::Parentheses: {

Callers

nothing calls this directly

Calls 11

CodeStyleCheckMethod · 0.80
GetDiagnosticResultsMethod · 0.80
GetVirtualFileMethod · 0.80
GetLineIndexMethod · 0.80
GetLineColMethod · 0.80
GetCodeMethod · 0.80
RangeClass · 0.50
PositionClass · 0.50
SpellCheckMethod · 0.45
NameStyleCheckMethod · 0.45
GetEndOffsetMethod · 0.45

Tested by

no test coverage detected