@@ -1526,23 +1526,26 @@ public IEnumerable<DiagnosticRecord> AnalyzeScriptDefinition(string scriptDefini
1526
1526
1527
1527
var relevantParseErrors = RemoveTypeNotFoundParseErrors ( errors , out List < DiagnosticRecord > diagnosticRecords ) ;
1528
1528
1529
- if ( relevantParseErrors != null && relevantParseErrors . Count > 0 )
1529
+ // Add parse errors first!
1530
+ if ( relevantParseErrors != null )
1530
1531
{
1531
- foreach ( var parseError in relevantParseErrors )
1532
+ List < DiagnosticRecord > results = new List < DiagnosticRecord > ( ) ;
1533
+ foreach ( var parseError in relevantParseErrors )
1532
1534
{
1533
1535
string parseErrorMessage = String . Format ( CultureInfo . CurrentCulture , Strings . ParseErrorFormatForScriptDefinition , parseError . Message . TrimEnd ( '.' ) , parseError . Extent . StartLineNumber , parseError . Extent . StartColumnNumber ) ;
1534
- this . outputWriter . WriteError ( new ErrorRecord ( new ParseException ( parseErrorMessage ) , parseErrorMessage , ErrorCategory . ParserError , parseError . ErrorId ) ) ;
1536
+ results . Add ( new DiagnosticRecord (
1537
+ parseError . Message ,
1538
+ parseError . Extent ,
1539
+ parseError . ErrorId . ToString ( ) ,
1540
+ DiagnosticSeverity . ParseError ,
1541
+ "" // no script file
1542
+ )
1543
+ ) ;
1535
1544
}
1545
+ diagnosticRecords . AddRange ( results ) ;
1536
1546
}
1537
1547
1538
- if ( relevantParseErrors != null && relevantParseErrors . Count > 10 )
1539
- {
1540
- string manyParseErrorMessage = String . Format ( CultureInfo . CurrentCulture , Strings . ParserErrorMessageForScriptDefinition ) ;
1541
- this . outputWriter . WriteError ( new ErrorRecord ( new ParseException ( manyParseErrorMessage ) , manyParseErrorMessage , ErrorCategory . ParserError , scriptDefinition ) ) ;
1542
-
1543
- return new List < DiagnosticRecord > ( ) ;
1544
- }
1545
-
1548
+ // now, analyze the script definition
1546
1549
return diagnosticRecords . Concat ( this . AnalyzeSyntaxTree ( scriptAst , scriptTokens , String . Empty ) ) ;
1547
1550
}
1548
1551
@@ -1839,49 +1842,8 @@ private IEnumerable<DiagnosticRecord> AnalyzeFile(string filePath)
1839
1842
this . outputWriter . WriteVerbose ( string . Format ( CultureInfo . CurrentCulture , Strings . VerboseFileMessage , filePath ) ) ;
1840
1843
var diagnosticRecords = new List < DiagnosticRecord > ( ) ;
1841
1844
1842
- //Parse the file
1843
- if ( File . Exists ( filePath ) )
1844
- {
1845
- // processing for non help script
1846
- if ( ! ( Path . GetFileName ( filePath ) . ToLower ( ) . StartsWith ( "about_" ) && Path . GetFileName ( filePath ) . ToLower ( ) . EndsWith ( ".help.txt" ) ) )
1847
- {
1848
- try
1849
- {
1850
- scriptAst = Parser . ParseFile ( filePath , out scriptTokens , out errors ) ;
1851
- }
1852
- catch ( Exception e )
1853
- {
1854
- this . outputWriter . WriteWarning ( e . ToString ( ) ) ;
1855
- return null ;
1856
- }
1857
- #if ! PSV3
1858
- //try parsing again
1859
- if ( TrySaveModules ( errors , scriptAst ) )
1860
- {
1861
- scriptAst = Parser . ParseFile ( filePath , out scriptTokens , out errors ) ;
1862
- }
1863
- #endif //!PSV3
1864
- var relevantParseErrors = RemoveTypeNotFoundParseErrors ( errors , out diagnosticRecords ) ;
1865
-
1866
- //Runspace.DefaultRunspace = oldDefault;
1867
- if ( relevantParseErrors != null && relevantParseErrors . Count > 0 )
1868
- {
1869
- foreach ( var parseError in relevantParseErrors )
1870
- {
1871
- string parseErrorMessage = String . Format ( CultureInfo . CurrentCulture , Strings . ParserErrorFormat , parseError . Extent . File , parseError . Message . TrimEnd ( '.' ) , parseError . Extent . StartLineNumber , parseError . Extent . StartColumnNumber ) ;
1872
- this . outputWriter . WriteError ( new ErrorRecord ( new ParseException ( parseErrorMessage ) , parseErrorMessage , ErrorCategory . ParserError , parseError . ErrorId ) ) ;
1873
- }
1874
- }
1875
-
1876
- if ( relevantParseErrors != null && relevantParseErrors . Count > 10 )
1877
- {
1878
- string manyParseErrorMessage = String . Format ( CultureInfo . CurrentCulture , Strings . ParserErrorMessage , System . IO . Path . GetFileName ( filePath ) ) ;
1879
- this . outputWriter . WriteError ( new ErrorRecord ( new ParseException ( manyParseErrorMessage ) , manyParseErrorMessage , ErrorCategory . ParserError , filePath ) ) ;
1880
- return new List < DiagnosticRecord > ( ) ;
1881
- }
1882
- }
1883
- }
1884
- else
1845
+ // If the file doesn't exist, return
1846
+ if ( ! File . Exists ( filePath ) )
1885
1847
{
1886
1848
this . outputWriter . ThrowTerminatingError ( new ErrorRecord ( new FileNotFoundException ( ) ,
1887
1849
string . Format ( CultureInfo . CurrentCulture , Strings . InvalidPath , filePath ) ,
@@ -1890,6 +1852,50 @@ private IEnumerable<DiagnosticRecord> AnalyzeFile(string filePath)
1890
1852
return null ;
1891
1853
}
1892
1854
1855
+ // short-circuited processing for a help file
1856
+ // no parsing can really be done, but there are other rules to run (specifically encoding).
1857
+ if ( Regex . Matches ( Path . GetFileName ( filePath ) , @"^about_.*help.txt$" , RegexOptions . IgnoreCase ) . Count != 0 )
1858
+ {
1859
+ return diagnosticRecords . Concat ( this . AnalyzeSyntaxTree ( scriptAst , scriptTokens , filePath ) ) ;
1860
+ }
1861
+
1862
+ // Process script
1863
+ try
1864
+ {
1865
+ scriptAst = Parser . ParseFile ( filePath , out scriptTokens , out errors ) ;
1866
+ }
1867
+ catch ( Exception e )
1868
+ {
1869
+ this . outputWriter . WriteWarning ( e . ToString ( ) ) ;
1870
+ return null ;
1871
+ }
1872
+ #if ! PSV3
1873
+ //try parsing again
1874
+ if ( TrySaveModules ( errors , scriptAst ) )
1875
+ {
1876
+ scriptAst = Parser . ParseFile ( filePath , out scriptTokens , out errors ) ;
1877
+ }
1878
+ #endif //!PSV3
1879
+ var relevantParseErrors = RemoveTypeNotFoundParseErrors ( errors , out diagnosticRecords ) ;
1880
+
1881
+ // First, add all parse errors
1882
+ if ( relevantParseErrors != null )
1883
+ {
1884
+ List < DiagnosticRecord > results = new List < DiagnosticRecord > ( ) ;
1885
+ foreach ( var parseError in relevantParseErrors )
1886
+ {
1887
+ string parseErrorMessage = String . Format ( CultureInfo . CurrentCulture , Strings . ParseErrorFormatForScriptDefinition , parseError . Message . TrimEnd ( '.' ) , parseError . Extent . StartLineNumber , parseError . Extent . StartColumnNumber ) ;
1888
+ results . Add ( new DiagnosticRecord (
1889
+ parseError . Message ,
1890
+ parseError . Extent ,
1891
+ parseError . ErrorId . ToString ( ) ,
1892
+ DiagnosticSeverity . ParseError ,
1893
+ filePath )
1894
+ ) ;
1895
+ }
1896
+ diagnosticRecords . AddRange ( results ) ;
1897
+ }
1898
+
1893
1899
return diagnosticRecords . Concat ( this . AnalyzeSyntaxTree ( scriptAst , scriptTokens , filePath ) ) ;
1894
1900
}
1895
1901
0 commit comments