|
1 | 1 | import { Event, EventEmitter, Position, ProviderResult, TreeDataProvider, TreeItem, TreeItemCollapsibleState, window, workspace } from "vscode"; |
2 | | -import { AnalyzerError, AnalyzerResult, Location, ParagraphError, ResultType, runAnalysis } from "./analyzer"; |
| 2 | +import { AnalyzerError, AnalyzerResult, HeaderError, Location, ParagraphError, ResultType, runAnalysis } from "./analyzer"; |
3 | 3 | import * as path from 'path'; |
4 | 4 |
|
5 | 5 | export default class TreeProvider implements TreeDataProvider<ResultsTreeItem> { |
@@ -41,11 +41,42 @@ export default class TreeProvider implements TreeDataProvider<ResultsTreeItem> { |
41 | 41 | this.generateParagraphErrors(<ParagraphFinding> element) |
42 | 42 | ); |
43 | 43 | } |
| 44 | + else if(element.label === 'Header') { |
| 45 | + return Promise.resolve( |
| 46 | + this.generateHeaderErrors(<HeaderFinding> element) |
| 47 | + ) |
| 48 | + } |
44 | 49 | else { |
45 | 50 | return Promise.resolve([]); |
46 | 51 | } |
47 | 52 | } |
48 | 53 |
|
| 54 | + generateHeaderErrors(element: HeaderFinding): FindingWithPosition[] { |
| 55 | + const startLocationToString = (loc: Location) => ( |
| 56 | + `Line:Column ${element.header.loc.start.line}:${element.header.loc.start.column}` |
| 57 | + ); |
| 58 | + const endLocationToString = (loc: Location) => ( |
| 59 | + `Line:Column ${element.header.loc.end.line}:${element.header.loc.end.column}` |
| 60 | + ); |
| 61 | + |
| 62 | + return [ |
| 63 | + new FindingWithPosition( |
| 64 | + "Start", |
| 65 | + startLocationToString(element.header.loc), |
| 66 | + element.header.loc, |
| 67 | + this, |
| 68 | + TreeItemCollapsibleState.None |
| 69 | + ), |
| 70 | + new FindingWithPosition( |
| 71 | + "End", |
| 72 | + endLocationToString(element.header.loc), |
| 73 | + element.header.loc, |
| 74 | + this, |
| 75 | + TreeItemCollapsibleState.None |
| 76 | + ) |
| 77 | + ]; |
| 78 | + } |
| 79 | + |
49 | 80 | generateParagraphErrors(element: ParagraphFinding): FindingWithPosition[] { |
50 | 81 |
|
51 | 82 | const startLocationToString = (loc: Location) => ( |
@@ -82,7 +113,11 @@ export default class TreeProvider implements TreeDataProvider<ResultsTreeItem> { |
82 | 113 | private generateBodyError(result: AnalyzerResult): Finding { |
83 | 114 | if (result instanceof ParagraphError) { |
84 | 115 | return new ParagraphFinding(result.title, result.message, result, this, TreeItemCollapsibleState.Collapsed); |
85 | | - } else { |
| 116 | + } |
| 117 | + else if (result instanceof HeaderError) { |
| 118 | + return new HeaderFinding(result.title, result.message, result, this, TreeItemCollapsibleState.Collapsed); |
| 119 | + } |
| 120 | + else { |
86 | 121 | return new Finding(result.title, result.message, this, TreeItemCollapsibleState.None); |
87 | 122 | } |
88 | 123 | } |
@@ -154,6 +189,18 @@ export class Finding extends ResultsTreeItem { |
154 | 189 | }; |
155 | 190 | } |
156 | 191 |
|
| 192 | +export class HeaderFinding extends Finding { |
| 193 | + constructor( |
| 194 | + public readonly label: string, |
| 195 | + public readonly description: string, |
| 196 | + public readonly header: HeaderError, |
| 197 | + public provider: TreeProvider, |
| 198 | + public readonly collapsibleState: TreeItemCollapsibleState |
| 199 | + ) { |
| 200 | + super(label, description, provider, collapsibleState); |
| 201 | + } |
| 202 | +} |
| 203 | + |
157 | 204 | export class ParagraphFinding extends Finding { |
158 | 205 | constructor( |
159 | 206 | public readonly label: string, |
|
0 commit comments