diff --git a/src/main/kotlin/com/intellij/plugin/powershell/lang/lsp/languagehost/PSLanguageHostUtils.kt b/src/main/kotlin/com/intellij/plugin/powershell/lang/lsp/languagehost/PSLanguageHostUtils.kt index 9d32835a..ee6140e8 100644 --- a/src/main/kotlin/com/intellij/plugin/powershell/lang/lsp/languagehost/PSLanguageHostUtils.kt +++ b/src/main/kotlin/com/intellij/plugin/powershell/lang/lsp/languagehost/PSLanguageHostUtils.kt @@ -56,7 +56,7 @@ object PSLanguageHostUtils { private suspend fun readPowerShellVersion(exePath: String): PSVersionInfo { var process: Process? = null val commandString = "(\$PSVersionTable.PSVersion, \$PSVersionTable.PSEdition) -join ' '" - val commandLine = GeneralCommandLine(exePath, "-Command", commandString) + val commandLine = GeneralCommandLine(exePath, "–NoProfile", "-Command", commandString) return coroutineScope { try { process = commandLine.createProcess() diff --git a/src/main/resources/PowerShell.bnf b/src/main/resources/PowerShell.bnf index 7df4d20b..4b3d4252 100644 --- a/src/main/resources/PowerShell.bnf +++ b/src/main/resources/PowerShell.bnf @@ -381,7 +381,7 @@ cast_expression ::= type_literal_expression unary_expression //private attributed_expression ::= type_literal variable -left pipeline_tail ::= ( PIPE nls? command_call_expression )+ +left pipeline_tail ::= ( nls? PIPE nls? command_call_expression )+ {elementType=pipeline} command_call_expression ::= command_invocation_operator ( (command_module command_name_expr command_element* ) | command_name_expr command_element* ) | command_name_expression command_element* diff --git a/src/test/kotlin/com/intellij/plugin/powershell/lang/PowerShellParserTest.kt b/src/test/kotlin/com/intellij/plugin/powershell/lang/PowerShellParserTest.kt index a52d7079..3b20f982 100644 --- a/src/test/kotlin/com/intellij/plugin/powershell/lang/PowerShellParserTest.kt +++ b/src/test/kotlin/com/intellij/plugin/powershell/lang/PowerShellParserTest.kt @@ -40,4 +40,5 @@ class PowerShellParserTest : ParsingTestCase("parser", "ps1", PowerShellParserDe fun testEnumDeclaration() { doTest(true) } fun testParamBlock() { doTest(true) } fun testComment() { doTest(true) } + fun testNewLineThenPipeOperator() { doTest(true) } } diff --git a/src/test/resources/testData/parser/NewLineThenPipeOperator.ps1 b/src/test/resources/testData/parser/NewLineThenPipeOperator.ps1 new file mode 100644 index 00000000..5ea7b022 --- /dev/null +++ b/src/test/resources/testData/parser/NewLineThenPipeOperator.ps1 @@ -0,0 +1,6 @@ +1, 2, 3 +| Foreach-Object { $_ } + +1, 2, 3 + +| Foreach-Object { $_ } diff --git a/src/test/resources/testData/parser/NewLineThenPipeOperator.txt b/src/test/resources/testData/parser/NewLineThenPipeOperator.txt new file mode 100644 index 00000000..aff1504f --- /dev/null +++ b/src/test/resources/testData/parser/NewLineThenPipeOperator.txt @@ -0,0 +1,64 @@ +FILE(0,65) + PowerShellPipelineTailImplGen(PIPELINE)(0,31) + PowerShellArrayLiteralExpressionImplGen(ARRAY_LITERAL_EXPRESSION)(0,7) + PowerShellIntegerLiteralExpressionImplGen(INTEGER_LITERAL_EXPRESSION)(0,1) + PsiElement(DEC_INTEGER)('1')(0,1) + PsiElement(,)(',')(1,2) + PsiWhiteSpace(' ')(2,3) + PowerShellIntegerLiteralExpressionImplGen(INTEGER_LITERAL_EXPRESSION)(3,4) + PsiElement(DEC_INTEGER)('2')(3,4) + PsiElement(,)(',')(4,5) + PsiWhiteSpace(' ')(5,6) + PowerShellIntegerLiteralExpressionImplGen(INTEGER_LITERAL_EXPRESSION)(6,7) + PsiElement(DEC_INTEGER)('3')(6,7) + PsiElement(NLS)('\n')(7,8) + PsiElement(|)('|')(8,9) + PsiWhiteSpace(' ')(9,10) + PowerShellCommandCallExpressionImplGen(COMMAND_CALL_EXPRESSION)(10,31) + PowerShellCommandNameImplGen(COMMAND_NAME)(10,24) + PowerShellIdentifierImplGen(IDENTIFIER)(10,24) + PsiElement(GENERIC_ID_PART)('Foreach-Object')(10,24) + PsiWhiteSpace(' ')(24,25) + PowerShellCommandArgumentImplGen(COMMAND_ARGUMENT)(25,31) + PowerShellScriptBlockExpressionImplGen(SCRIPT_BLOCK_EXPRESSION)(25,31) + PsiElement({)('{')(25,26) + PsiWhiteSpace(' ')(26,27) + PowerShellBlockBodyImplGen(BLOCK_BODY)(27,29) + PowerShellTargetVariableExpressionImplGen(TARGET_VARIABLE_EXPRESSION)(27,29) + PsiElement($)('$')(27,28) + PowerShellIdentifierImplGen(IDENTIFIER)(28,29) + PsiElement(SIMPLE_ID)('_')(28,29) + PsiWhiteSpace(' ')(29,30) + PsiElement(})('}')(30,31) + PsiElement(NLS)('\n\n')(31,33) + PowerShellPipelineTailImplGen(PIPELINE)(33,65) + PowerShellArrayLiteralExpressionImplGen(ARRAY_LITERAL_EXPRESSION)(33,40) + PowerShellIntegerLiteralExpressionImplGen(INTEGER_LITERAL_EXPRESSION)(33,34) + PsiElement(DEC_INTEGER)('1')(33,34) + PsiElement(,)(',')(34,35) + PsiWhiteSpace(' ')(35,36) + PowerShellIntegerLiteralExpressionImplGen(INTEGER_LITERAL_EXPRESSION)(36,37) + PsiElement(DEC_INTEGER)('2')(36,37) + PsiElement(,)(',')(37,38) + PsiWhiteSpace(' ')(38,39) + PowerShellIntegerLiteralExpressionImplGen(INTEGER_LITERAL_EXPRESSION)(39,40) + PsiElement(DEC_INTEGER)('3')(39,40) + PsiElement(NLS)('\n\n')(40,42) + PsiElement(|)('|')(42,43) + PsiWhiteSpace(' ')(43,44) + PowerShellCommandCallExpressionImplGen(COMMAND_CALL_EXPRESSION)(44,65) + PowerShellCommandNameImplGen(COMMAND_NAME)(44,58) + PowerShellIdentifierImplGen(IDENTIFIER)(44,58) + PsiElement(GENERIC_ID_PART)('Foreach-Object')(44,58) + PsiWhiteSpace(' ')(58,59) + PowerShellCommandArgumentImplGen(COMMAND_ARGUMENT)(59,65) + PowerShellScriptBlockExpressionImplGen(SCRIPT_BLOCK_EXPRESSION)(59,65) + PsiElement({)('{')(59,60) + PsiWhiteSpace(' ')(60,61) + PowerShellBlockBodyImplGen(BLOCK_BODY)(61,63) + PowerShellTargetVariableExpressionImplGen(TARGET_VARIABLE_EXPRESSION)(61,63) + PsiElement($)('$')(61,62) + PowerShellIdentifierImplGen(IDENTIFIER)(62,63) + PsiElement(SIMPLE_ID)('_')(62,63) + PsiWhiteSpace(' ')(63,64) + PsiElement(})('}')(64,65) \ No newline at end of file