-
Notifications
You must be signed in to change notification settings - Fork 727
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2638 from anjiazhuyouxing/feat/json-viewer-error-…
…display Feat/json viewer error display
- Loading branch information
Showing
13 changed files
with
159 additions
and
18 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
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
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
41 changes: 41 additions & 0 deletions
41
packages/semi-json-viewer-core/src/view/error/errorWidget.ts
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,41 @@ | ||
import { Diagnostic } from '../../service/jsonTypes'; | ||
import { Emitter, getEmitter } from '../../common/emitter'; | ||
import { View } from '../view'; | ||
import { GlobalEvents } from '../../common/emitterEvents'; | ||
|
||
export class ErrorWidget { | ||
private _view: View; | ||
private emitter: Emitter<GlobalEvents> = getEmitter(); | ||
constructor(view: View) { | ||
this._view = view; | ||
this._attachEventListeners(); | ||
} | ||
|
||
private _attachEventListeners() { | ||
this.emitter.on('problemsChanged', (result: any) => { | ||
this.renderErrorLine(result.problems); | ||
}); | ||
} | ||
|
||
private renderErrorLine(problems: Diagnostic[]) { | ||
problems.forEach((problem: Diagnostic) => { | ||
const { start, end } = problem.range; | ||
const errMessage = problem.message; | ||
this.findDomByPos(start, end, errMessage); | ||
}); | ||
} | ||
|
||
private findDomByPos(start: { lineNumber: number; column: number }, end: { lineNumber: number; column: number }, errMessage: string) { | ||
const line = this._view.getLineElement(start.lineNumber); | ||
if (!line) return; | ||
let offset = 1; | ||
for (let i = 0; i < line.children.length; i++) { | ||
const child = line.children[i]; | ||
offset += child.textContent?.length || 0; | ||
if (offset > start.column && offset <= end.column) { | ||
const className = 'semi-json-viewer-error'; | ||
child.classList.add(className); | ||
} | ||
} | ||
} | ||
} |
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