/********************************************************************************
 * Copyright (C) 2017 TypeFox and others.
 *
 * This program and the accompanying materials are made available under the
 * terms of the Eclipse Public License v. 2.0 which is available at
 * http://www.eclipse.org/legal/epl-2.0.
 *
 * This Source Code may also be made available under the following Secondary
 * Licenses when the conditions for such availability set forth in the Eclipse
 * Public License v. 2.0 are satisfied: GNU General Public License, version 2
 * with the GNU Classpath Exception which is available at
 * https://www.gnu.org/software/classpath/license.html.
 *
 * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
 ********************************************************************************/ import { ProblemMarker } from '../../common/problem-marker' ; import { ProblemManager } from './problem-manager' ; import { ProblemCompositeTreeNode } from './problem-composite-tree-node' ; import { MarkerNode , MarkerTree , MarkerOptions , MarkerInfoNode } from '../marker-tree' ; import { MarkerTreeModel } from '../marker-tree-model' ; import { injectable , inject } from '@theia/core/shared/inversify' ; import { OpenerOptions , TreeNode } from '@theia/core/lib/browser' ; import { Marker } from '../../common/marker' ; import { Diagnostic } from '@theia/core/shared/vscode-languageserver-protocol' ; import { ProblemUtils } from './problem-utils' ; @ injectable ( ) export class ProblemTree extends MarkerTree < Diagnostic > { constructor ( @ inject ( ProblemManager ) protected readonly problemManager , @ inject ( MarkerOptions ) protected readonly markerOptions ) { super ( problemManager , markerOptions ) ; } protected getMarkerNodes ( parent , markers ) { const nodes = super . getMarkerNodes ( parent , markers ) ; return nodes . sort ( ( a , b ) => this . sortMarkers ( a , b ) ) ; } param a param b protected sortMarkers ( a , b ) { const markerA = a . marker as Marker < Diagnostic > ; const markerB = b . marker as Marker < Diagnostic > ; const severity = ProblemUtils . severityCompareMarker ( markerA , markerB ) ; if ( severity !== 0 ) { return severity ; } const lineNumber = ProblemUtils . lineNumberCompare ( markerA , markerB ) ; if ( lineNumber !== 0 ) { return lineNumber ; } const columnNumber = ProblemUtils . columnNumberCompare ( markerA , markerB ) ; if ( columnNumber !== 0 ) { return columnNumber ; } const owner = ProblemUtils . ownerCompare ( markerA , markerB ) ; if ( owner !== 0 ) { return owner ; } return 0 ; } protected insertNodeWithMarkers ( node , markers ) { ProblemCompositeTreeNode . addChild ( node . parent , node , markers ) ; const children = this . getMarkerNodes ( node , markers ) ; node . numberOfMarkers = markers . length ; this . setChildren ( node , children ) ; } } @ injectable ( ) export class ProblemTreeModel extends MarkerTreeModel { @ inject ( ProblemManager ) protected readonly problemManager : ProblemManager ; protected getOpenerOptionsByMarker ( node ) { if ( ProblemMarker . is ( node . marker ) ) { return { selection : node . marker . data . range } ; } return undefined ; } removeNode ( node ) { if ( MarkerInfoNode . is ( node ) ) { this . problemManager . cleanAllMarkers ( node . uri ) ; } if ( MarkerNode . is ( node ) ) { const { uri } = node ; const { owner } = node . marker ; const diagnostics = this . problemManager . findMarkers ( { uri , owner , dataFilter : data => node . marker . data !== data } ) . map ( ( { data } ) => data ) ; this . problemManager . setMarkers ( uri , owner , diagnostics ) ; } } }