forked from JBakamovic/yavide
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement clang diagnostics/fixits service. Make it play with Vim Qui…
…ckFix. This is a second service now for which we are supposed to be providing feedback as we are typing (the same is with semantic syntax highlighting). Therefore, some refactoring had to take place in order to put these under a common denominator: now there is a common, 'TextChangedI', event which we are now using to hook all services on which are supposed to be running like this. This avoids code duplication and makes it easier for future integrations.
- Loading branch information
1 parent
a00d5b6
commit 81a085c
Showing
8 changed files
with
210 additions
and
74 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
Empty file.
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,12 @@ | ||
import logging | ||
import time | ||
|
||
class Diagnostics(): | ||
def __init__(self, parser, callback = None): | ||
self.parser = parser | ||
self.callback = callback | ||
|
||
def __call__(self, args): | ||
diagnostics_iter = self.parser.get_diagnostics() | ||
if self.callback: | ||
self.callback(diagnostics_iter, args) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import logging | ||
from common.yavide_utils import YavideUtils | ||
|
||
class VimQuickFixDiagnostics(): | ||
def __init__(self, yavide_instance): | ||
self.yavide_instance = yavide_instance | ||
|
||
def __call__(self, diagnostics_iter, args): | ||
def clang_severity_to_quickfix_type(severity): | ||
# Clang severity | Vim Quickfix type | ||
# ---------------------------------- | ||
# Ignored = 0 0 () | ||
# Note = 1 I (info) | ||
# Warning = 2 W (warning) | ||
# Error = 3 E (error) | ||
# Fatal = 4 other () | ||
# ---------------------------------- | ||
if severity == 0: | ||
return '0' | ||
elif severity == 1: | ||
return 'I' | ||
elif severity == 2: | ||
return 'W' | ||
elif severity == 3: | ||
return 'E' | ||
elif severity == 4: | ||
return 'other' | ||
return '0' | ||
|
||
diagnostics = [] | ||
for d in diagnostics_iter: | ||
diagnostics.append( | ||
"{'bufnr': '" + str(args[0]) + "', " + | ||
"'lnum': '" + str(d.location.line) + "', " + | ||
"'col': '" + str(d.location.column) + "', " + | ||
"'type': '" + clang_severity_to_quickfix_type(d.severity) + "', " + | ||
"'text': '" + d.category_name + " | " + str(d.spelling).replace("'", r"") + "'}" | ||
) | ||
|
||
fixits = "Hint:" | ||
for f in d.fixits: | ||
fixits += \ | ||
" Try using '" + str(f.value) + "' instead. [col=" + \ | ||
str(f.range.start.column) + ":" + str(f.range.end.column) + "]" | ||
# TODO How to handle multiline quickfix entries? It would be nice show each fixit in its own line. | ||
|
||
if len(d.fixits): | ||
diagnostics.append( | ||
"{'bufnr': '" + str(args[0]) + "', " + | ||
"'lnum': '" + str(d.location.line) + "', " + | ||
"'col': '" + str(d.location.column) + "', " + | ||
"'type': 'I', " + | ||
"'text': '" + str(fixits).replace("'", r"") + "'}" | ||
) | ||
|
||
YavideUtils.call_vim_remote_function(self.yavide_instance, "Y_SrcCodeDiagnostics_Apply(" + str(diagnostics).replace('"', r"") + ")") | ||
logging.debug("Diagnostics: " + str(diagnostics)) | ||
|