@@ -5,7 +5,7 @@ import { PanelManager } from './panel/PanelManager';
55import { CommandExecutor } from './commands/CommandExecutor' ;
66import { DiagnosticManager } from './diagnostics/DiagnosticManager' ;
77import { getFileInfo , parseLintResult , parseMetaschemaResult , errorPositionToRange , parseCliError , hasJsonParseErrors } from './utils/fileUtils' ;
8- import { PanelState , WebviewToExtensionMessage } from '../../protocol/types' ;
8+ import { LintError , PanelState , WebviewToExtensionMessage } from '../../protocol/types' ;
99import { DiagnosticType } from './types' ;
1010
1111let panelManager : PanelManager ;
@@ -35,8 +35,8 @@ export async function activate(context: vscode.ExtensionContext): Promise<void>
3535 // Only disable validation if a workspace is open to avoid changing global user settings
3636 if ( vscode . workspace . workspaceFolders ) {
3737 await vscode . workspace . getConfiguration ( 'json' ) . update (
38- 'validate.enable' ,
39- false ,
38+ 'validate.enable' ,
39+ false ,
4040 vscode . ConfigurationTarget . Workspace
4141 ) ;
4242 }
@@ -105,15 +105,15 @@ function handleWebviewMessage(message: WebviewToExtensionMessage): void {
105105 }
106106 vscode . window . showTextDocument ( lastActiveTextEditor . document , showOptions ) . then ( ( editor ) => {
107107 editor . selection = new vscode . Selection ( range . start , range . end ) ;
108-
108+
109109 editor . revealRange ( range , vscode . TextEditorRevealType . InCenter ) ;
110110 } ) ;
111111 } else if ( message . command === 'openExternal' && message . url ) {
112112 vscode . env . openExternal ( vscode . Uri . parse ( message . url ) ) ;
113113 } else if ( message . command === 'formatSchema' && lastActiveTextEditor ) {
114114 const filePath = lastActiveTextEditor . document . uri . fsPath ;
115115 const fileInfo = getFileInfo ( filePath ) ;
116-
116+
117117 if ( ! fileInfo || ! panelManager . exists ( ) || ! currentPanelState ) {
118118 return ;
119119 }
@@ -138,14 +138,14 @@ function handleWebviewMessage(message: WebviewToExtensionMessage): void {
138138 if ( lastActiveTextEditor ) {
139139 await vscode . window . showTextDocument ( lastActiveTextEditor . document , lastActiveTextEditor . viewColumn ) ;
140140 }
141-
141+
142142 // Wait for Huge schemas to reload after formatting
143143 await new Promise ( resolve => setTimeout ( resolve , 300 ) ) ;
144144
145145 await updatePanelContent ( ) ;
146146 } ) . catch ( ( error ) => {
147147 let errorMessage = error . message ;
148-
148+
149149 // Try to parse JSON error from CLI
150150 const cliError = parseCliError ( error . message ) ;
151151 if ( cliError ) {
@@ -157,7 +157,7 @@ function handleWebviewMessage(message: WebviewToExtensionMessage): void {
157157 }
158158 }
159159 }
160-
160+
161161 vscode . window . showErrorMessage ( `Format failed: ${ errorMessage } ` ) ;
162162 if ( currentPanelState ) {
163163 const updatedState = {
@@ -217,7 +217,7 @@ function handleActiveEditorChange(editor: vscode.TextEditor | undefined): void {
217217 * Handle document save events
218218 */
219219function handleDocumentSave ( document : vscode . TextDocument ) : void {
220- if ( panelManager . exists ( ) && lastActiveTextEditor &&
220+ if ( panelManager . exists ( ) && lastActiveTextEditor &&
221221 document . uri . fsPath === lastActiveTextEditor . document . uri . fsPath ) {
222222 const fileInfo = getFileInfo ( document . uri . fsPath ) ;
223223 // Only refresh if it's a JSON/YAML file
@@ -227,6 +227,26 @@ function handleDocumentSave(document: vscode.TextDocument): void {
227227 }
228228}
229229
230+ /**
231+ * Sort the Linting Errors by line location
232+ */
233+ function sortLintErrorsByLocation ( errors : LintError [ ] ) : LintError [ ] {
234+ return [ ...errors ] . sort ( ( a , b ) => {
235+ if ( ! a . position && ! b . position ) return 0 ;
236+ if ( ! a . position ) return 1 ;
237+ if ( ! b . position ) return - 1 ;
238+
239+ const [ aLine , aColumn ] = a . position ;
240+ const [ bLine , bColumn ] = b . position ;
241+
242+ if ( aLine !== bLine ) {
243+ return aLine - bLine ;
244+ }
245+
246+ return aColumn - bColumn ;
247+ } ) ;
248+ }
249+
230250/**
231251 * Update the panel content with current file analysis
232252 */
@@ -313,6 +333,11 @@ async function updatePanelContent(): Promise<void> {
313333
314334 const lintResult = parseLintResult ( lintOutput ) ;
315335
336+ if ( lintResult . errors && lintResult . errors . length > 0 ) {
337+ // TODO: Consider moving lint diagnostic ordering to the jsonschema CLI
338+ lintResult . errors = sortLintErrorsByLocation ( lintResult . errors ) ;
339+ }
340+
316341 const parseErrors = hasJsonParseErrors ( lintResult , metaschemaResult ) ;
317342
318343 const finalState : PanelState = {
0 commit comments