import * as vscode from 'vscode' ; import * as path from 'path' ; import { DevToolsExtensionContext } from "../devToolsExtensionContext" ; import { JsonFormEditor } from "./jsonFormEditor" ; import { CARuleInfo } from "../langserver/caRuleInfo" ; import { ToolsGetCodeAnalyzersRulesRequest } from '../langserver/toolsGetCodeAnalyzersRulesRequest' ; import { basename } from 'path' ; export class RuleSetEditor extends JsonFormEditor { protected _analyzers : string [ ] ; constructor ( devToolsContext ) { super ( devToolsContext , "RuleSet" ) ; this . fieldsOrder = [ "name" , "description" , "generalAction" , "includedRuleSets" , "rules" ] ; this . _analyzers = [ "${AppSourceCop}" , "${CodeCop}" , "${PerTenantExtensionCop}" , "${UICop}" ] ; } protected getViewType ( ) { return 'azALDevTools.AppJsonEditor' ; } protected onDocumentLoaded ( ) { super . onDocumentLoaded ( ) ; this . loadRules ( ) ; } protected loadAnalyzers ( ) { let uri = undefined ; if ( this . document ) uri = this . document . uri ; let alConfig = vscode . workspace . getConfiguration ( 'al' , uri ) ; let codeAnalyzersSetting = alConfig . get < string [ ] | undefined > ( "codeAnalyzers" ) ; if ( codeAnalyzersSetting ) { for ( let i = 0 ; i < codeAnalyzersSetting . length ; i ++ ) { if ( ! codeAnalyzersSetting [ i ] . startsWith ( '${' ) ) { this . _analyzers . push ( path . parse ( codeAnalyzersSetting [ i ] ) . name ) ; } } } } protected async loadRules ( ) { await vscode . window . withProgress ( { location : vscode . ProgressLocation . Notification , title : "Loading code analyzers rules" } , async ( progress ) => { let rules = [ ] ; this . loadAnalyzers ( ) ; for ( let analyzerIdx = 0 ; analyzerIdx < this . _analyzers . length ; analyzerIdx ++ ) { let request = new ToolsGetCodeAnalyzersRulesRequest ( this . _analyzers [ analyzerIdx ] ) ; let response = await this . _devToolsContext . toolsLangServerClient . getCodeAnalyzersRules ( request ) ; if ( ( response ) && ( response . rules ) ) { for ( let ruleIdx = 0 ; ruleIdx < response . rules . length ; ruleIdx ++ ) { response . rules [ ruleIdx ] . analyzer = this . _analyzers [ analyzerIdx ] ; if ( response . rules [ ruleIdx ] . id ) rules . push ( { value : response . rules [ ruleIdx ] . id , description : response . rules [ ruleIdx ] . description } ) ; } } } if ( rules . length > 0 ) { this . sendMessage ( { command : 'setAutocomplete' , path : [ 'rules' , 'id' ] , data : rules } ) ; } } ) ; } protected getFieldsDefinition ( ) { return [ { "caption" : "General" , "type" : "group" } , { "name" : "name" , "caption" : "Name" , "description" : "The name of the rule set." , "type" : "string" } , { "name" : "description" , "caption" : "Description" , "description" : "The description of the rule set" , "type" : "string" } , { "name" : "generalAction" , "caption" : "General Action" , "description" : "The action to apply to all the diagnostics that have a Default action specified." , "type" : "string" , "autocomplete" : [ "Error" , "Warning" , "Info" , "Hidden" ] } , { "caption" : "Rules" , "type" : "group" } , { "name" : "rules" , "caption" : "Rules" , "description" : "Collection of rules to be applied to diagnostics generated by this analyzer." , "type" : "array" , "fields" : [ { "name" : "id" , "caption" : "Id" , "description" : "The string that uniquely identifies a diagnostic." , "type" : "string" , "style" : "width: 80px;" } , { "name" : "action" , "caption" : "Action" , "description" : "The action to apply if the diagnostic is emitted." , "type" : "string" , "autocomplete" : [ "Error" , "Warning" , "Info" , "Hidden" , "None" ] , "style" : "width: 80px;" } , { "name" : "justification" , "caption" : "Justification" , "description" : "The justification for this rule." , "type" : "string" } ] } , { "caption" : "Include Rule Sets" , "type" : "group" } , { "name" : "includedRuleSets" , "caption" : "Include Rule Sets" , "description" : "List of external rule set files to include in the current rule set." , "type" : "array" , "fields" : [ { "name" : "action" , "caption" : "Action" , "autocomplete" : [ "Error" , "Warning" , "Info" , "Hidden" , "None" , "Default" ] , "style" : "width: 80px;" , "description" : "The action to apply for all the diagnostics that have a Default action specified in the included rule set." } , { "name" : "path" , "caption" : "Path" , "type" : "string" , "description" : "The path to the included file. The path can be absolute or relative to the project folder." } ] } ] ; } }