-
Notifications
You must be signed in to change notification settings - Fork 625
Context messages #1770
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Context messages #1770
Changes from 10 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
e89eeab
Display diagnostic messages
johnpryan f48bafa
Merge branch 'master' of github.com:dart-lang/dart-pad
johnpryan f7b75a8
Show links on issues if available, add hover CSS to issues
johnpryan 67e343c
Add correction messages
johnpryan d4de778
Tweak layout of analysis errors + correction messages
johnpryan 02126fa
oops'd the server urls
johnpryan 2056fc0
remove outdated parameter
johnpryan cee555f
Run dart format --fix
johnpryan 7b37db6
format protobuf file
johnpryan e3d71fb
fix link styles
johnpryan b1c0648
Rename LineInfo -> Location
johnpryan a2a930c
keep periods at the end of analyzer messages
johnpryan 7e69e34
change - line x to (line x)
johnpryan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -25,10 +25,10 @@ class AnalysisResultsController { | |
| final DElement toggle; | ||
| bool _flashHidden; | ||
|
|
||
| final StreamController<AnalysisIssue> _onClickController = | ||
| final StreamController<LineInfo> _onClickController = | ||
| StreamController.broadcast(); | ||
|
|
||
| Stream<AnalysisIssue> get onIssueClick => _onClickController.stream; | ||
| Stream<LineInfo> get onItemClicked => _onClickController.stream; | ||
|
|
||
| AnalysisResultsController(this.flash, this.message, this.toggle) { | ||
| // Show issues by default, but hide the flash element (otherwise an empty | ||
|
|
@@ -70,29 +70,89 @@ class AnalysisResultsController { | |
| message.text = '$amount ${amount == 1 ? 'issue' : 'issues'}'; | ||
|
|
||
| flash.clearChildren(); | ||
| for (var elem in issues.map(_issueElement)) { | ||
| for (var issue in issues) { | ||
| var elem = _issueElement(issue); | ||
| flash.add(elem); | ||
|
|
||
| for (var diagnostic in issue.diagnosticMessages) { | ||
| var diagnosticElement = _diagnosticElement(diagnostic); | ||
| flash.add(diagnosticElement); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| Element _issueElement(AnalysisIssue issue) { | ||
| var message = issue.message; | ||
| if (issue.message.endsWith('.')) { | ||
| message = message.substring(0, message.length - 1); | ||
| } | ||
| message = _stripPeriod(message); | ||
|
|
||
| var elem = DivElement()..classes.add('issue'); | ||
| var elem = DivElement()..classes.addAll(['issue', 'clickable']); | ||
|
|
||
| elem.children.add(SpanElement() | ||
| ..text = issue.kind | ||
| ..classes.addAll(_classesForType[issue.kind])); | ||
|
|
||
| elem.children.add(SpanElement() | ||
| var columnElem = DivElement()..classes.add('issue-column'); | ||
|
|
||
| var messageSpan = DivElement() | ||
| ..text = '$message - line ${issue.line}' | ||
| ..classes.add('message'); | ||
| columnElem.children.add(messageSpan); | ||
|
|
||
| // Add the correction, if any. | ||
| if (issue.correction != null && issue.correction.isNotEmpty) { | ||
| var correctionMessage = _stripPeriod(issue.correction); | ||
| columnElem.children.add(DivElement() | ||
| ..text = correctionMessage | ||
| ..classes.add('message')); | ||
| } | ||
|
|
||
| // Add a link to the documentation | ||
| if (issue.url != null && issue.url.isNotEmpty) { | ||
| columnElem.children.add(AnchorElement() | ||
| ..href = issue.url | ||
| ..text = ' Open Documentation' | ||
| ..target = '_blank' | ||
| ..classes.add('issue-anchor')); | ||
| } | ||
|
|
||
| elem.children.add(columnElem); | ||
|
|
||
| elem.onClick.listen((_) { | ||
| _onClickController.add(LineInfo( | ||
| line: issue.line, | ||
| charStart: issue.charStart, | ||
| charLength: issue.charLength)); | ||
| }); | ||
|
|
||
| return elem; | ||
| } | ||
|
|
||
| String _stripPeriod(String s) { | ||
| if (s.endsWith('.')) { | ||
| s = s.substring(0, s.length - 1); | ||
| } | ||
| return s; | ||
| } | ||
|
|
||
| Element _diagnosticElement(DiagnosticMessage diagnosticMessage) { | ||
| var message = diagnosticMessage.message; | ||
| if (message.endsWith('.')) { | ||
| message = message.substring(0, message.length - 1); | ||
| } | ||
|
|
||
| var elem = DivElement()..classes.addAll(['issue', 'clickable']); | ||
|
|
||
| elem.children.add(SpanElement()..classes.add('issue-indent')); | ||
|
|
||
| elem.children.add(SpanElement() | ||
| ..text = message | ||
| ..classes.add('message')); | ||
|
|
||
| elem.onClick.listen((_) { | ||
| _onClickController.add(issue); | ||
| _onClickController.add(LineInfo( | ||
| line: diagnosticMessage.line, | ||
| charStart: diagnosticMessage.charStart, | ||
| charLength: diagnosticMessage.charLength)); | ||
| }); | ||
|
|
||
| return elem; | ||
|
|
@@ -118,3 +178,15 @@ class AnalysisResultsController { | |
| toggle.text = _hideMsg; | ||
| } | ||
| } | ||
|
|
||
| class LineInfo { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You may want to consider a slightly more specific name, like TextRange or SelectionRange or something. Just a thought. |
||
| final int line; | ||
| final int charStart; | ||
| final int charLength; | ||
|
|
||
| LineInfo({ | ||
| this.line, | ||
| this.charStart, | ||
| this.charLength, | ||
| }); | ||
| } | ||
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm kind of surprised there isn't already a class with these properties in the codebase, but I can't find one. There's
Positionin/lib/editing/editor.dart, but it doesn't include length.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or, given that
Positionis identical in structure to the interfacePositionfrom LSP, consider using the LSP interfaceRangeinstead. Although it might not be as convenient for your purposes.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Location type is used in AnalysisError and DiagnosticMessage classes, so
dart-servicesadds the line, charStart, and charLength to an AnalysisIssue protocol buffer message that the client gets. The client doesn't actually use the analysis_server_lib package at the moment.We could add two new
PostitionandRangemessages to our protocol buffer, but that might be out of scope here.