@@ -8,7 +8,7 @@ import { ServerManager } from "../ServerManager";
8
8
import Provider from "./Provider" ;
9
9
10
10
const lineNumber = / \( ( [ ^ ) ] + ) \) / ;
11
- const lineMessage = / E r r o r : ( .* ) / ;
11
+ const lineMessage = / ( E r r o r | W a r n i n g ) : ( .* ) / ;
12
12
const lineFilename = / ^ [ ^ ( ] + / ;
13
13
14
14
enum OS {
@@ -30,11 +30,7 @@ export default class DiagnoticsProvider extends Provider {
30
30
) ;
31
31
}
32
32
33
- private sendDiagnostics ( uri : string , diagnostics : Diagnostic [ ] ) {
34
- this . server . connection . sendDiagnostics ( { uri, diagnostics } ) ;
35
- }
36
-
37
- private generateDiagnostic ( uris : string [ ] , files : FilesDiagnostics , severity : DiagnosticSeverity ) {
33
+ private generateDiagnostics ( uris : string [ ] , files : FilesDiagnostics , severity : DiagnosticSeverity ) {
38
34
return ( line : string ) => {
39
35
const uri = uris . find ( ( uri ) => basename ( fileURLToPath ( uri ) ) === lineFilename . exec ( line ) ! [ 0 ] ) ;
40
36
@@ -73,8 +69,8 @@ export default class DiagnoticsProvider extends Provider {
73
69
74
70
private publish ( uri : string ) {
75
71
return async ( ) => {
76
- return await new Promise ( ( resolve , reject ) => {
77
- const { enabled, nwnHome, nwnInstallation, verbose } = this . server . config . compiler ;
72
+ return await new Promise < boolean > ( ( resolve , reject ) => {
73
+ const { enabled, nwnHome, reportWarnings , nwnInstallation, verbose } = this . server . config . compiler ;
78
74
if ( ! enabled ) {
79
75
return resolve ( true ) ;
80
76
}
@@ -149,67 +145,62 @@ export default class DiagnoticsProvider extends Provider {
149
145
} ) ;
150
146
151
147
child . on ( "close" , ( _ ) => {
152
- try {
153
- const lines = stdout
154
- . toString ( )
155
- . split ( "\n" )
156
- . filter ( ( line ) => line !== "\r" && line !== "\n" && Boolean ( line ) ) ;
157
- const errors : string [ ] = [ ] ;
158
- const warnings : string [ ] = [ ] ;
159
-
160
- lines . forEach ( ( line ) => {
161
- if ( verbose && ! line . includes ( "Compiling:" ) ) {
162
- this . server . logger . info ( line ) ;
163
- }
148
+ const lines = stdout
149
+ . toString ( )
150
+ . split ( "\n" )
151
+ . filter ( ( line ) => line !== "\r" && line !== "\n" && Boolean ( line ) ) ;
152
+ const errors : string [ ] = [ ] ;
153
+ const warnings : string [ ] = [ ] ;
154
+
155
+ lines . forEach ( ( line ) => {
156
+ if ( verbose && ! line . includes ( "Compiling:" ) ) {
157
+ this . server . logger . info ( line ) ;
158
+ }
164
159
165
- // Diagnostics
166
- if ( line . includes ( "Error:" ) ) {
167
- errors . push ( line ) ;
168
- }
169
- if ( line . includes ( "Warning:" ) ) {
170
- warnings . push ( line ) ;
171
- }
160
+ // Diagnostics
161
+ if ( line . includes ( "Error:" ) ) {
162
+ errors . push ( line ) ;
163
+ }
164
+ if ( reportWarnings && line . includes ( "Warning:" ) ) {
165
+ warnings . push ( line ) ;
166
+ }
172
167
173
- // Actual errors
174
- if ( line . includes ( "NOTFOUND" ) ) {
168
+ // Actual errors
169
+ if ( line . includes ( "NOTFOUND" ) ) {
170
+ return this . server . logger . error (
171
+ "Unable to resolve nwscript.nss. Are your Neverwinter Nights home and/or installation directories valid?" ,
172
+ ) ;
173
+ }
174
+ if ( line . includes ( "Failed to open .key archive" ) ) {
175
+ return this . server . logger . error (
176
+ "Unable to open nwn_base.key Is your Neverwinter Nights installation directory valid?" ,
177
+ ) ;
178
+ }
179
+ if ( line . includes ( "Unable to read input file" ) ) {
180
+ if ( Boolean ( nwnHome ) || Boolean ( nwnInstallation ) ) {
175
181
return this . server . logger . error (
176
- "Unable to resolve nwscript.nss. Are your Neverwinter Nights home and/or installation directories valid? " ,
182
+ "Unable to resolve provided Neverwinter Nights home and/or installation directories. Ensure the paths are valid in the extension settings. " ,
177
183
) ;
178
- }
179
- if ( line . includes ( "Failed to open .key archive" ) ) {
184
+ } else {
180
185
return this . server . logger . error (
181
- "Unable to open nwn_base.key Is your Neverwinter Nights installation directory valid? " ,
186
+ "Unable to automatically resolve Neverwinter Nights home and/or installation directories. " ,
182
187
) ;
183
188
}
184
- if ( line . includes ( "Unable to read input file" ) ) {
185
- if ( Boolean ( nwnHome ) || Boolean ( nwnInstallation ) ) {
186
- return this . server . logger . error (
187
- "Unable to resolve provided Neverwinter Nights home and/or installation directories. Ensure the paths are valid in the extension settings." ,
188
- ) ;
189
- } else {
190
- return this . server . logger . error (
191
- "Unable to automatically resolve Neverwinter Nights home and/or installation directories." ,
192
- ) ;
193
- }
194
- }
195
- } ) ;
196
-
197
- if ( verbose ) {
198
- this . server . logger . info ( "Done.\n" ) ;
199
189
}
190
+ } ) ;
191
+
192
+ if ( verbose ) {
193
+ this . server . logger . info ( "Done.\n" ) ;
194
+ }
200
195
201
- uris . push ( document . uri ) ;
202
- errors . forEach ( this . generateDiagnostic ( uris , files , DiagnosticSeverity . Error ) ) ;
203
- warnings . forEach ( this . generateDiagnostic ( uris , files , DiagnosticSeverity . Warning ) ) ;
196
+ uris . push ( document . uri ) ;
197
+ errors . forEach ( this . generateDiagnostics ( uris , files , DiagnosticSeverity . Error ) ) ;
198
+ if ( reportWarnings ) warnings . forEach ( this . generateDiagnostics ( uris , files , DiagnosticSeverity . Warning ) ) ;
204
199
205
- for ( const [ uri , diagnostics ] of Object . entries ( files ) ) {
206
- this . sendDiagnostics ( uri , diagnostics ) ;
207
- }
208
- resolve ( true ) ;
209
- } catch ( e : any ) {
210
- this . server . logger . error ( e . message ) ;
211
- reject ( e ) ;
200
+ for ( const [ uri , diagnostics ] of Object . entries ( files ) ) {
201
+ this . server . connection . sendDiagnostics ( { uri, diagnostics } ) ;
212
202
}
203
+ resolve ( true ) ;
213
204
} ) ;
214
205
} ) ;
215
206
} ;
0 commit comments