-
-
Notifications
You must be signed in to change notification settings - Fork 379
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
introduce diagnosticmanager instead of using a callback approach
- Loading branch information
1 parent
e37587b
commit 8bc6836
Showing
8 changed files
with
98 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
internal/arduino/builder/internal/diagnosticmanager/diagnosticmanager.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package diagnosticmanager | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/arduino/arduino-cli/internal/arduino/builder/internal/diagnostics" | ||
"github.com/sirupsen/logrus" | ||
) | ||
|
||
type Manager struct { | ||
results diagnostics.Diagnostics | ||
lastInsertIndex int | ||
} | ||
|
||
func New() *Manager { | ||
return &Manager{lastInsertIndex: -1} | ||
} | ||
|
||
func (m *Manager) ParseOutput(cmdline []string, out []byte) { | ||
compiler := diagnostics.DetectCompilerFromCommandLine( | ||
cmdline, | ||
false, // at the moment compiler-probing is not required | ||
) | ||
if compiler == nil { | ||
logrus.Warnf("Could not detect compiler from: %s", cmdline) | ||
return | ||
} | ||
diags, err := diagnostics.ParseCompilerOutput(compiler, out) | ||
if err != nil { | ||
logrus.Warnf("Error parsing compiler output: %s", err) | ||
return | ||
} | ||
m.lastInsertIndex += len(diags) | ||
m.results = append(m.results, diags...) | ||
} | ||
|
||
func (m *Manager) DiscardLastInsert() { | ||
if m.lastInsertIndex < 0 { | ||
return | ||
} | ||
m.results = m.results[:m.lastInsertIndex] | ||
m.lastInsertIndex = len(m.results) - 1 | ||
} | ||
|
||
func (m *Manager) CompilerDiagnostics() diagnostics.Diagnostics { | ||
// When producing the preprocessing diagnostics, we might have duplicates | ||
// caused by the run of the libraries detector and the sketch preprocessing. | ||
if len(m.results) <= 1 { | ||
return nil | ||
} | ||
mp := map[string]*diagnostics.Diagnostic{} | ||
keys := []string{} | ||
for _, v := range m.results { | ||
key := fmt.Sprintf("%s:%d:%d:%s", v.File, v.Line, v.Column, v.Severity) | ||
if _, ok := mp[key]; !ok { | ||
mp[key] = v | ||
keys = append(keys, key) | ||
} | ||
} | ||
s := make(diagnostics.Diagnostics, len(mp)) | ||
for i, k := range keys { | ||
s[i] = mp[k] | ||
} | ||
return s | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters