Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…, #202) Connect TODOs with the issues, TODO cleanup
  • Loading branch information
ForNeVeR committed Mar 3, 2024
1 parent baccc65 commit 9b08293
Show file tree
Hide file tree
Showing 21 changed files with 4,556 additions and 4,571 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ private void setBundledPowerShellExtensionPath() throws ConfigurationException {
}

void fillPowerShellInfo(@NotNull LSPInitMain.PowerShellInfo powerShellInfo) {
setEditorServicesVersionLabelValue(powerShellInfo.getEditorServicesModuleVersion());//todo make consistent with 'setPowerShellExtensionPath'
setEditorServicesVersionLabelValue(powerShellInfo.getEditorServicesModuleVersion());
setPowerShellExtensionPath(powerShellInfo.getPowerShellExtensionPath());
setPowerShellExePath(powerShellInfo.getPowerShellExePath());
psExecutableChooserPanel.setPowerShellVersionLabelValue(powerShellInfo.getPowerShellVersion());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class PowerShellStringManipulator : AbstractElementManipulator<PowerShellStringL
val oldText = element.node.text
val contentRange = element.getContentRange()
val newString = oldText.substring(0, contentRange.startOffset) + escapeString(element, newContent) + oldText.substring(contentRange.endOffset)
// val newString = oldText.substring(0, range.startOffset) + escapeString(element, newContent) + oldText.substring(range.endOffset)//todo fix range to use it from parameter
// val newString = oldText.substring(0, range.startOffset) + escapeString(element, newContent) + oldText.substring(range.endOffset)//TODO[#190]: fix range to use it from parameter
val stringLiteral = PowerShellPsiElementFactory.createExpression(element.project, newString)
return element.replace(stringLiteral) as PowerShellStringLiteralExpression
}
Expand Down Expand Up @@ -63,9 +63,9 @@ class PowerShellStringManipulator : AbstractElementManipulator<PowerShellStringL
return PowerShellStringUtil.escapeHereStringCharacters(text, "$", false, true, StringBuilder()).toString()
}

//todo implement in PowerShellStringUtil.escapeStringCharacters()
//TODO[#191]: implement in PowerShellStringUtil.escapeStringCharacters()
private fun escapeQuotes(str: String?, quoteChar: Char, escapeChar: Char): String {
return str?.replace("$quoteChar", "$escapeChar$quoteChar") ?: ""
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import com.intellij.refactoring.rename.RenamePsiElementProcessor
class PowerShellRenamePsiElementProcessor : RenamePsiElementProcessor() {
override fun canProcessElement(element: PsiElement): Boolean = element is PowerShellComponent
override fun findReferences(element: PsiElement, searchScope: SearchScope, searchInCommentsAndStrings: Boolean): MutableCollection<PsiReference> {
if (element is PowerShellComponent && nameHasSubExpression(element)) {//todo it's workaround to resort to findUsage handler because default index does not contain needed tokens
if (element is PowerShellComponent && nameHasSubExpression(element)) {//TODO[#192]: it's workaround to resort to findUsage handler because default index does not contain needed tokens
val findManager = FindManager.getInstance(element.getProject()) as? FindManagerImpl
?: return super.findReferences(element, searchScope, searchInCommentsAndStrings)
val findUsagesManager = findManager.findUsagesManager
Expand All @@ -32,4 +32,4 @@ class PowerShellRenamePsiElementProcessor : RenamePsiElementProcessor() {
override fun getNewName(): String = nameSuggestionsField.enteredName
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ object PowerShellResolveUtil {
}

override fun visitArrayClassType(o: PowerShellArrayClassType): Boolean {
val componentType = o.getComponentType()//todo resolve to the actual array class (PS actually tries to resolve to component type in some cases)
val componentType = o.getComponentType()//TODO[#194]: resolve to the actual array class (PS actually tries to resolve to component type in some cases)
return if (componentType is PowerShellClassType) {
processClassType(componentType)
} else {
Expand Down Expand Up @@ -123,8 +123,8 @@ object PowerShellResolveUtil {
val baseDeclaration = baseClass.resolve()
if (baseDeclaration is PowerShellTypeDeclaration && processMembers(baseDeclaration, resolveProcessor)) return true
}
//todo create fake PSI element for default constructor?
//TODO[#195]: create fake PSI element for default constructor?
return resolveProcessor.getResult().isNotEmpty()
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class PowerShellResolver<T> : ResolveCache.AbstractResolver<T, List<PowerShellRe
}

abstract class PowerShellReferenceResolveProcessor<out R : PowerShellReferencePsiElement>(protected val myRef: R) : PsiScopeProcessor {
private var myResult: PowerShellResolveResult? = null //todo should navigate to closest declaration (of function or variable)
private var myResult: PowerShellResolveResult? = null //TODO[#193]: should navigate to closest declaration (of function or variable)

fun getResult(): PowerShellResolveResult? {
return myResult
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ fun getModuleVersion(moduleBase: String, moduleName: String): String {
val lines = FileUtil.loadLines(moduleFile)
for (l in lines) {
if (l.contains("ModuleVersion", true)) {
//todo can be not in one line
//TODO[#196]: can be not in one line
return l.trimStart { c -> c != '=' }.substringAfter('=').trim().trim { c -> c == '\'' }
}
}
Expand All @@ -48,4 +48,4 @@ fun join(vararg pathPart: String): String {

fun getDefaultWorkingDirectory(): String {
return EnvironmentUtil.getValue("HOME") ?: System.getProperty("user.home") ?: System.getProperty("user.dir") ?: ""
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,6 @@ enum class PowerShellComponentType(icon: Icon) {
CompletionItemKind.Enum -> ENUM
CompletionItemKind.File -> GENERIC_FILE
CompletionItemKind.Text -> TEXT
// CompletionItemKind.Color -> TODO()
// CompletionItemKind.Snippet -> TODO()
// CompletionItemKind.Keyword -> TODO()
// CompletionItemKind.Reference -> TODO()
// CompletionItemKind.Value -> TODO()
// CompletionItemKind.Unit -> TODO()
else -> null
}
}
Expand All @@ -83,4 +77,4 @@ enum class PowerShellComponentType(icon: Icon) {
}


}
}
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ class PSLanguageClientImpl(private val project: Project) : LanguageClient, Endpo
* to wait for an answer from the client.
*/
override fun showMessageRequest(requestParams: ShowMessageRequestParams): CompletableFuture<MessageActionItem> {
TODO("Not implemented")
error("Not supported")
}

/**
Expand All @@ -139,4 +139,4 @@ class PSLanguageClientImpl(private val project: Project) : LanguageClient, Endpo
Unsupported,
OK
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -223,11 +223,10 @@ open class EditorServicesLanguageHostStarter(protected val myProject: Project) :
psesVersionString = "-EditorServicesVersion '$psesVersionString'"
}
val bundledModulesPath = getPSExtensionModulesDir(psExtensionPath)
val additionalModules = ""//todo check if something could be added here
val useReplSwitch = if (useConsoleRepl()) "-EnableConsoleRepl" else ""
val logLevel = if (useConsoleRepl()) "Normal" else "Diagnostic"
val args = "$psesVersionString -HostName '${myHostDetails.name}' -HostProfileId '${myHostDetails.profileId}' " +
"-HostVersion '${myHostDetails.version}' -AdditionalModules @($additionalModules) " +
"-HostVersion '${myHostDetails.version}' -AdditionalModules @() " +
"-BundledModulesPath '$bundledModulesPath' $useReplSwitch " +
"-LogLevel '$logLevel' -LogPath '$logPath' -SessionDetailsPath '$sessionDetailsPath' -FeatureFlags @() $splitInOutPipesSwitch"
val preamble =
Expand Down Expand Up @@ -286,7 +285,6 @@ open class EditorServicesLanguageHostStarter(protected val myProject: Project) :
)

val fileWithSessionInfo = getSessionDetailsFile()
//todo retry starting language service process one more time
if (!waitForSessionFile(fileWithSessionInfo)) {
process.destroyForcibly()
return null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ class LanguageServerEndpoint(
ensureStarted()
val capabilities = getServerCapabilities()
if (capabilities != null) {
//todo move it to LanguageHostConnectionManager (notify it when server initialized)
languageServer?.workspaceService?.didChangeConfiguration(DEFAULT_DID_CHANGE_CONFIGURATION_PARAMS)//notify Editor Services to start REPL loop
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ open class PowerShellInvocationExpressionImpl(node: ASTNode) : PowerShellQualifi

override fun multiResolve(incompleteCode: Boolean): Array<PowerShellResolveResult> {
if (isConstructorCall()) {
//todo where is the best place to implement resolve to a default constructor?
//TODO[#195] where is the best place to implement resolve to a default constructor?
val qType = getQualifierType()
if (qType is PowerShellClassType) {
val qClass = qType.resolve()
Expand All @@ -46,4 +46,4 @@ open class PowerShellInvocationExpressionImpl(node: ASTNode) : PowerShellQualifi

private fun isConstructorCall() = PsNames.CONSTRUCTOR_CALL.equals(referenceName, true)

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ abstract class PowerShellQualifiedReferenceExpression(node: ASTNode) : PowerShel
}

protected open fun inferTypeFromResolved(resolved: PowerShellComponent): PowerShellType {
//todo create function type and return function image here
//TODO[#198]: create function type and return function image here
if (resolved is PowerShellAttributesHolder) resolved.getAttributeList().mapNotNull { it.typeLiteralExpression }.forEach { return it.getType() }
return PowerShellType.UNKNOWN
}
Expand Down Expand Up @@ -52,4 +52,4 @@ abstract class PowerShellQualifiedReferenceExpression(node: ASTNode) : PowerShel
return qualifier?.getType()
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ abstract class PowerShellReferencePsiElementImpl(node: ASTNode) : PowerShellPsiE
return PowerShellResolveUtil.toCandidateInfoArray2(elements)
}

override fun getNameElement(): PsiElement? = findChildByClass(PowerShellIdentifier::class.java) //todo
override fun getNameElement(): PsiElement? = findChildByClass(PowerShellIdentifier::class.java) //TODO[#199]:

override fun getElement(): PsiElement = this

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ open class PowerShellTargetVariableImpl(node: ASTNode) : PowerShellAbstractCompo
override fun getType(): PowerShellType {
//in case of $this variable resolves to class declaration
if (isInstanceThis()) {
//todo where create it (need somewhere in PSI element getType())?
val enclosingType = resolve()
if (enclosingType is PowerShellTypeDeclaration) return PowerShellImmediateClassTypeImpl(enclosingType)
}
Expand Down Expand Up @@ -86,7 +85,6 @@ open class PowerShellTargetVariableImpl(node: ASTNode) : PowerShellAbstractCompo
override fun getElement(): PsiElement = this

override fun resolve(): PowerShellComponent? {
//todo resolve it in Resolver
if (isInstanceThis()) return PsiTreeUtil.findFirstContext(this, false) { c -> c is PowerShellTypeDeclaration } as? PowerShellComponent
val res = multiResolve(false)
return if (res.isEmpty()) this else res[0].element
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class PowerShellArrayClassTypeImpl(private val psiElement: PowerShellArrayTypeEl
return "[" + getName() + "]"
}

override fun resolve(): PowerShellComponent? {//todo resolve to the actual array class
override fun resolve(): PowerShellComponent? {//TODO[#194] resolve to the actual array class
val componentType = getComponentType()
return (componentType as? PowerShellClassType)?.resolve()
}
Expand All @@ -31,4 +31,4 @@ class PowerShellArrayClassTypeImpl(private val psiElement: PowerShellArrayTypeEl
return psiElement.referenceTypeElement.referenceName ?: PsNames.UNNAMED
}

}
}
14 changes: 6 additions & 8 deletions src/main/resources/PowerShell.bnf
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ node_block ::= node_token nls? command_argument_list+
private node_token ::= SIMPLE_ID
//node_name ::= primary_expression | statement_rule | identifier //function_name

resource_block ::= resource_type nls? ( resource_name nls? resource_block_tail | resource_block_tail )//todo: or predicate is faster?
resource_block ::= resource_type nls? ( resource_name nls? resource_block_tail | resource_block_tail )
private resource_block_tail ::= LCURLY nls? resource_block_body? nls? RCURLY
resource_block_body ::= hash_literal_body
{elementType=block_body}
Expand Down Expand Up @@ -395,14 +395,14 @@ command_call_expression ::= command_invocation_operator ( (command_module comman
implements='com.intellij.plugin.powershell.psi.PowerShellQualifiedReferenceElement<com.intellij.plugin.powershell.psi.PowerShellExpression>'
mixin='com.intellij.plugin.powershell.psi.impl.PowerShellInvocationExpressionImpl'
*/
private command_name_expression ::= path_expression | command_name//todo parse path_item where appropriate: path_item all bare identifiers including command_name
private command_name_expression ::= path_expression | command_name
command_name ::= command_name_identifier //generic_token
command_name_identifier ::= generic_token_with_sub_expr | generic_token_part //generic_token
{elementType=identifier}



private generic_token_with_sub_expr ::= generic_token_with_subexpr_start statement_list? RP nws command_name //todo word index is not built by default words scanner
private generic_token_with_sub_expr ::= generic_token_with_subexpr_start statement_list? RP nws command_name

private generic_token_with_subexpr_start ::= generic_token_part nws DS nws LP

Expand Down Expand Up @@ -687,7 +687,7 @@ path_expression ::= path_item nws (
| (PATH_SEP nws path_item)+ //just container+
| (COLON|DS) (nws PATH_SEP)? // just drive
| PATH_SEP //just PATH_SEP
) | PATH_SEP (nws (path_expression | path_item))?//todo do not produce another path_expression node
) | PATH_SEP (nws (path_expression | path_item))?
| relative_path_item // just relative path
path_item ::= path_item_name
relative_path_item ::= relative_path
Expand All @@ -700,8 +700,6 @@ private relative_path ::= DOT | DOT_DOT | PATH_SEP
command_parameter ::= CMD_PARAMETER | binary_operator
private binary_operator ::= OP_C | OP_NOT | OP_BNOT | OP_BAND | OP_BOR | OP_BXOR | OP_AND | OP_OR | OP_XOR
verbatim_command_argument ::= VERBATIM_ARG_START VERBATIM_ARG_INPUT //(verbatim_command_string | AMP_ARG | generic_token_chars )+
//private verbatim_command_string ::= EXPANDABLE_STRING //TODO: 02/09/17 variable substitution:


private primary_expression ::= value (invocation_expression | member_access_expression | element_access_expression | post_increment_expression | post_decrement_expression)*

Expand All @@ -727,7 +725,7 @@ private expression_list_rule ::= expression ( nls? COMMA nls? expression)*
left post_increment_expression ::= PP
left post_decrement_expression ::= MM

private member_name ::= simple_name_reference //todo reference_expression ? (to be able to use 'function type' for it)
private member_name ::= simple_name_reference
| string_literal_expression
//-> | string_literal_with_subexpression
| expression_with_unary_operator //prefix_op unary_expression //
Expand Down Expand Up @@ -815,7 +813,7 @@ label ::= ':' nws label_name
mixin="com.intellij.plugin.powershell.psi.impl.PowerShellAbstractComponent"
implements="com.intellij.plugin.powershell.psi.PowerShellComponent"
}
label_name ::= SIMPLE_ID// todo ALNUM?
label_name ::= SIMPLE_ID// TODO[#202]: ALNUM?
{elementType=identifier}

private nws ::= <<isNotWhiteSpace>>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ class PowerShellCodeInsightTest : BasePlatformTestCase() {
"}\n",
"var array = {`\"1`\":`\"2`\"}`nfor (var obj in array) {`n obj.concat(`\"1234`\",`\"1212112`\",`\"22222`\")`n}`n")

//sub-expressions todo missingValue
//sub-expressions TODO[#197]: missingValue
// checkInjectedText("This is a sample \"string\" with \$( Write-Output \"Sub-expression\" )end \$( Write-Output \"Sub-expression \" ) \"of\" string.",
// "This is a sample `\"string`\" with \$( Write-Output \"Sub-expression\" )end \$( Write-Output \"Sub-expression \" ) `\"of`\" string.")

Expand Down Expand Up @@ -250,4 +250,4 @@ class PowerShellCodeInsightTest : BasePlatformTestCase() {
return PsiTreeUtil.findChildOfType(file, PowerShellStringLiteralExpression::class.java) ?: error("text='$nodeText'")
}

}
}
6 changes: 3 additions & 3 deletions src/test/resources/testData/parser/PathExpression.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ Not-Path-Arg 42d
#Starting in Windows PowerShell 5.0, you can run
Get-ItemPropertyValue -Path HKLM:\SOFTWARE\Microsoft\PowerShell\3\PowerShellEngine -Name ApplicationBase

cd (Get-Location)\pip #command with 2 arguments: (Get-Location) and \pip todo: check it is really works
cd (Get-Location)\pip #command with 2 arguments: (Get-Location) and \pip TODO[#200]: check it is really works
cd (Get-Location)\pip\(Get-Location)\
cd \pip
cd \pip\wwe

#drive name in unc path
#drive name in unc path
$acl = Get-Acl \$(hostname)\e$\"some folder"

foreach ($srv in (Get-ChildItem HKLM:\SYSTEM\CurrentControlSet\Services\ts*).Name) {}
foreach ($srv in (Get-ChildItem HKLM:\SYSTEM\CurrentControlSet\Services\ts*).Name) {}
Loading

0 comments on commit 9b08293

Please sign in to comment.