|
1 | 1 | package ls |
2 | 2 |
|
3 | 3 | import ( |
4 | | - "fmt" |
5 | | - |
6 | 4 | "github.com/arduino/arduino-language-server/sourcemapper" |
7 | 5 | "go.bug.st/lsp" |
8 | 6 | "go.bug.st/lsp/jsonrpc" |
@@ -69,79 +67,35 @@ func (ls *INOLanguageServer) clang2IdeDocumentHighlight(logger jsonrpc.FunctionL |
69 | 67 | }, nil |
70 | 68 | } |
71 | 69 |
|
72 | | -func (ls *INOLanguageServer) clang2IdeDiagnostics(logger jsonrpc.FunctionLogger, clangDiagsParams *lsp.PublishDiagnosticsParams) ([]*lsp.PublishDiagnosticsParams, error) { |
73 | | - clangURI := clangDiagsParams.URI |
74 | | - if !ls.clangURIRefersToIno(clangURI) { |
75 | | - ideDiags := []lsp.Diagnostic{} |
76 | | - ideDiagsURI := lsp.DocumentURI{} |
77 | | - for _, clangDiag := range clangDiagsParams.Diagnostics { |
78 | | - ideURI, ideRange, err := ls.clang2IdeRangeAndDocumentURI(logger, clangURI, clangDiag.Range) |
79 | | - if err != nil { |
80 | | - return nil, err |
81 | | - } |
82 | | - if ideURI.String() == sourcemapper.NotInoURI.String() { |
83 | | - continue |
84 | | - } |
85 | | - if ideDiagsURI.String() == "" { |
86 | | - ideDiagsURI = ideURI |
87 | | - } else if ideDiagsURI.String() != ideURI.String() { |
88 | | - return nil, fmt.Errorf("unexpected URI %s: it should be %s", ideURI, ideURI) |
89 | | - } |
90 | | - ideDiag := clangDiag |
91 | | - ideDiag.Range = ideRange |
92 | | - ideDiags = append(ideDiags, ideDiag) |
93 | | - } |
94 | | - return []*lsp.PublishDiagnosticsParams{ |
95 | | - { |
96 | | - URI: ideDiagsURI, |
97 | | - Diagnostics: ideDiags, |
98 | | - }, |
99 | | - }, nil |
100 | | - } |
| 70 | +func (ls *INOLanguageServer) clang2IdeDiagnostics(logger jsonrpc.FunctionLogger, clangDiagsParams *lsp.PublishDiagnosticsParams) (map[lsp.DocumentURI]*lsp.PublishDiagnosticsParams, error) { |
| 71 | + // If diagnostics comes from sketch.ino.cpp they may refer to multiple .ino files, |
| 72 | + // so we collect all of the into a map. |
| 73 | + allIdeDiagsParams := map[lsp.DocumentURI]*lsp.PublishDiagnosticsParams{} |
101 | 74 |
|
102 | | - // Diagnostics coming from sketch.ino.cpp refers to all .ino files, so it must update |
103 | | - // the diagnostics list of all .ino files altogether. |
104 | | - // XXX: maybe this logic can be moved outside of this conversion function, make it much |
105 | | - // more straighforward. |
106 | | - allIdeInoDiagsParams := map[lsp.DocumentURI]*lsp.PublishDiagnosticsParams{} |
107 | | - for ideInoURI := range ls.ideInoDocsWithDiagnostics { |
108 | | - allIdeInoDiagsParams[ideInoURI] = &lsp.PublishDiagnosticsParams{ |
109 | | - URI: ideInoURI, |
110 | | - Diagnostics: []lsp.Diagnostic{}, |
111 | | - } |
112 | | - } |
113 | | - ls.ideInoDocsWithDiagnostics = map[lsp.DocumentURI]bool{} |
114 | | - |
115 | | - for _, clangDiag := range clangDiagsParams.Diagnostics { |
116 | | - ideURI, ideRange, err := ls.clang2IdeRangeAndDocumentURI(logger, clangURI, clangDiag.Range) |
| 75 | + for _, clangDiagnostic := range clangDiagsParams.Diagnostics { |
| 76 | + ideURI, ideRange, err := ls.clang2IdeRangeAndDocumentURI(logger, clangDiagsParams.URI, clangDiagnostic.Range) |
117 | 77 | if err != nil { |
118 | 78 | return nil, err |
119 | 79 | } |
120 | 80 | if ideURI.String() == sourcemapper.NotInoURI.String() { |
121 | 81 | continue |
122 | 82 | } |
123 | 83 |
|
124 | | - ideInoDiagsParams, ok := allIdeInoDiagsParams[ideURI] |
| 84 | + ideDiagsParams, ok := allIdeDiagsParams[ideURI] |
125 | 85 | if !ok { |
126 | | - ideInoDiagsParams = &lsp.PublishDiagnosticsParams{ |
| 86 | + ideDiagsParams = &lsp.PublishDiagnosticsParams{ |
127 | 87 | URI: ideURI, |
128 | 88 | Diagnostics: []lsp.Diagnostic{}, |
129 | 89 | } |
130 | | - allIdeInoDiagsParams[ideURI] = ideInoDiagsParams |
| 90 | + allIdeDiagsParams[ideURI] = ideDiagsParams |
131 | 91 | } |
132 | 92 |
|
133 | | - ideInoDiag := clangDiag |
| 93 | + ideInoDiag := clangDiagnostic |
134 | 94 | ideInoDiag.Range = ideRange |
135 | | - ideInoDiagsParams.Diagnostics = append(ideInoDiagsParams.Diagnostics, ideInoDiag) |
136 | | - |
137 | | - ls.ideInoDocsWithDiagnostics[ideURI] = true |
| 95 | + ideDiagsParams.Diagnostics = append(ideDiagsParams.Diagnostics, ideInoDiag) |
138 | 96 | } |
139 | 97 |
|
140 | | - ideInoDiagParams := []*lsp.PublishDiagnosticsParams{} |
141 | | - for _, v := range allIdeInoDiagsParams { |
142 | | - ideInoDiagParams = append(ideInoDiagParams, v) |
143 | | - } |
144 | | - return ideInoDiagParams, nil |
| 98 | + return allIdeDiagsParams, nil |
145 | 99 | } |
146 | 100 |
|
147 | 101 | func (ls *INOLanguageServer) clang2IdeSymbolInformation(clangSymbolsInformation []lsp.SymbolInformation) []lsp.SymbolInformation { |
|
0 commit comments