1+ import * as vscode from 'vscode' ;
2+ import { getFlowrSession } from './extension' ;
3+ import { LintingRuleNames , LintingRuleResult , LintingRules } from '@eagleoutice/flowr/linter/linter-rules' ;
4+ import { FilePathValidityResult } from '@eagleoutice/flowr/linter/rules/2-file-path-validity' ;
5+ import { DeprecatedFunctionsResult } from '@eagleoutice/flowr/linter/rules/1-deprecated-functions' ;
6+
7+ export function registerLintCommands ( context : vscode . ExtensionContext , output : vscode . OutputChannel ) {
8+ const linter = new LinterService ( output ) ;
9+ context . subscriptions . push ( vscode . commands . registerCommand ( 'vscode-flowr.lint.run' , async ( ) => {
10+ await linter . runLinting ( )
11+ } ) ) ;
12+ }
13+
14+ class LinterService {
15+ private readonly output : vscode . OutputChannel ;
16+ private readonly collection = vscode . languages . createDiagnosticCollection ( 'flowr-lint' ) ;
17+
18+ constructor ( output : vscode . OutputChannel ) {
19+ this . output = output ;
20+ }
21+
22+ async runLinting ( ) : Promise < void > {
23+ const activeEditor = vscode . window . activeTextEditor ;
24+
25+ if ( ! activeEditor ) {
26+ return ;
27+ }
28+
29+ const diagnostics : vscode . Diagnostic [ ] = [ ] ;
30+ this . output . appendLine ( `[Lint] Analyzing document: ${ activeEditor . document . fileName } ` ) ;
31+ const session = await getFlowrSession ( ) ;
32+
33+ const lint = await session . retrieveQuery ( activeEditor . document , [ { type : 'linter' } ] ) ;
34+
35+ for ( const [ ruleName , findings ] of Object . entries ( lint . result . linter . results ) ) {
36+ const rule = LintingRules [ ruleName as LintingRuleNames ] ;
37+
38+ this . output . appendLine ( `[Lint] Found ${ findings . results . length } issues for rule: ${ ruleName } ` ) ;
39+ this . output . appendLine ( `[Lint] ${ JSON . stringify ( findings ) } ` ) ;
40+
41+ for ( const finding of findings . results ) {
42+ const range = new vscode . Range (
43+ finding . range [ 0 ] - 1 ,
44+ finding . range [ 1 ] - 1 ,
45+ finding . range [ 2 ] - 1 ,
46+ finding . range [ 3 ] - 1
47+ ) ;
48+ diagnostics . push (
49+ new vscode . Diagnostic (
50+ range ,
51+ ruleName + ': ' + rule . prettyPrint ( finding as LintingRuleResult < LintingRuleNames > ) ,
52+ vscode . DiagnosticSeverity . Warning
53+ )
54+ ) ;
55+ }
56+ }
57+
58+ this . collection . set ( activeEditor . document . uri , diagnostics ) ;
59+ }
60+ }
0 commit comments