···131131 .option("--strictPort", `[boolean] exit if specified port is already in use`)
132132 .option(
133133 "--force",
134134- `[boolean] force the optimizer to ignore the cache and re-bundle`,
134134+ `[boolean] force the optimizer to ignore the cache and re-bundle`
135135 )
136136 .action((root, options) => {
137137 console.log(`Starting dev server at ${root || "."} with options:`, options);
···193193 // Completion for --config
194194 flagMap.set(optionKey, async (previousArgs, toComplete) => {
195195 const configFiles = ["vite.config.ts", "vite.config.js"].filter(
196196- (file) => file.startsWith(toComplete),
196196+ (file) => file.startsWith(toComplete)
197197 );
198198 return configFiles.map((file) => ({ action: file }));
199199 });
+50-57
powershell.ts
···5757 # Make sure the $Command is longer then the $CursorPosition before we truncate.
5858 # This happens because the $Command does not include the last space.
5959 if ($Command.Length -gt $CursorPosition) {
6060- $Command=$Command.Substring(0,$CursorPosition)
6060+ $Command = $Command.Substring(0, $CursorPosition)
6161 }
6262 __${name}_debug "Truncated command: $Command"
6363···6868 $ShellCompDirectiveFilterDirs=${ShellCompDirectiveFilterDirs}
6969 $ShellCompDirectiveKeepOrder=${ShellCompDirectiveKeepOrder}
70707171- # Original exec value
7272- $originalExec = "${exec}"
7373-7474- # Split the exec string by spaces to handle each part
7575- $execParts = $originalExec -split ' '
7676-7777- __${name}_debug "Value of exec: ${exec}"
7878-7971 # Prepare the command to request completions for the program.
8072 # Split the command at the first space to separate the program and arguments.
8181- $Program,$Arguments = $Command.Split(" ",2)
7373+ $Program, $Arguments = $Command.Split(" ", 2)
82748375 $RequestComp = "& ${exec} complete -- $Arguments"
8476 __${name}_debug "RequestComp: $RequestComp"
85778686- # We cannot use $WordToComplete because it
7878+ # we cannot use $WordToComplete because it
8779 # has the wrong values if the cursor was moved
8880 # so use the last argument
8981 if ($WordToComplete -ne "" ) {
···9183 }
9284 __${name}_debug "New WordToComplete: $WordToComplete"
93858686+9487 # Check for flag with equal sign
9588 $IsEqualFlag = ($WordToComplete -Like "--*=*" )
9689 if ( $IsEqualFlag ) {
9790 __${name}_debug "Completing equal sign flag"
9891 # Remove the flag part
9999- $Flag,$WordToComplete = $WordToComplete.Split("=",2)
9292+ $Flag, $WordToComplete = $WordToComplete.Split("=", 2)
10093 }
1019410295 if ( $WordToComplete -eq "" -And ( -Not $IsEqualFlag )) {
10396 # If the last parameter is complete (there is a space following it)
104104- # We add an extra empty parameter so we can indicate this to the program.
9797+ # We add an extra empty parameter so we can indicate this to the go method.
10598 __${name}_debug "Adding extra empty parameter"
10699 # PowerShell 7.2+ changed the way how the arguments are passed to executables,
107100 # so for pre-7.2 or when Legacy argument passing is enabled we need to use
108108- # \`"\`" to pass an empty argument, a "" or '' does not work!!!
109101 if ($PSVersionTable.PsVersion -lt [version]'7.2.0' -or
110102 ($PSVersionTable.PsVersion -lt [version]'7.3.0' -and -not [ExperimentalFeature]::IsEnabled("PSNativeCommandArgumentPassing")) -or
111103 (($PSVersionTable.PsVersion -ge [version]'7.3.0' -or [ExperimentalFeature]::IsEnabled("PSNativeCommandArgumentPassing")) -and
112104 $PSNativeCommandArgumentPassing -eq 'Legacy')) {
113105 $RequestComp="$RequestComp" + ' \`"\`"'
114106 } else {
115115- $RequestComp="$RequestComp" + ' ""'
107107+ $RequestComp = "$RequestComp" + ' ""'
116108 }
117109 }
118110119119- __${name}_debug "Calling: $RequestComp"
120120- # First disable ActiveHelp which is not supported for PowerShell
111111+ __${name}_debug "Calling $RequestComp"
112112+ # First disable ActiveHelp which is not supported for Powershell
113113+ $env:ActiveHelp = 0
121114122122- # Call the command, store the output in $out, and redirect stderr and stdout to null
123123- # $Out is an array containing each line per element
115115+ # call the command store the output in $out and redirect stderr and stdout to null
116116+ # $Out is an array contains each line per element
124117 Invoke-Expression -OutVariable out "$RequestComp" 2>&1 | Out-Null
125118126126- # Get directive from last line
119119+ # get directive from last line
127120 [int]$Directive = $Out[-1].TrimStart(':')
128121 if ($Directive -eq "") {
129122 # There is no directive specified
···131124 }
132125 __${name}_debug "The completion directive is: $Directive"
133126134134- # Remove directive (last element) from out
127127+ # remove directive (last element) from out
135128 $Out = $Out | Where-Object { $_ -ne $Out[-1] }
136129 __${name}_debug "The completions are: $Out"
137130138131 if (($Directive -band $ShellCompDirectiveError) -ne 0 ) {
139139- # Error code. No completion.
140140- __${name}_debug "Received error from custom completion code"
132132+ # Error code. No completion.
133133+ __${name}_debug "Received error from custom completion go code"
141134 return
142135 }
143136144137 $Longest = 0
145138 [Array]$Values = $Out | ForEach-Object {
146146- # Split the output into name and description
147147- $Name, $Description = $_.Split("t",2)
139139+ # Split the output in name and description
140140+ $Name, $Description = $_.Split("\`t", 2)
148141 __${name}_debug "Name: $Name Description: $Description"
149142150150- # Look for the longest completion to format things nicely
143143+ # Look for the longest completion so that we can format things nicely
151144 if ($Longest -lt $Name.Length) {
152145 $Longest = $Name.Length
153146 }
154147155155- # Set the description to a one-space string if none is set
156156- # This is needed because CompletionResult does not accept an empty string
148148+ # Set the description to a one space string if there is none set.
149149+ # This is needed because the CompletionResult does not accept an empty string as argument
157150 if (-Not $Description) {
158151 $Description = " "
159152 }
160160- @{Name="$Name";Description="$Description"}
153153+ @{ Name = "$Name"; Description = "$Description" }
161154 }
162155156156+163157 $Space = " "
164158 if (($Directive -band $ShellCompDirectiveNoSpace) -ne 0 ) {
165165- # Remove the space here
159159+ # remove the space here
166160 __${name}_debug "ShellCompDirectiveNoSpace is called"
167161 $Space = ""
168162 }
169163170164 if ((($Directive -band $ShellCompDirectiveFilterFileExt) -ne 0 ) -or
171165 (($Directive -band $ShellCompDirectiveFilterDirs) -ne 0 )) {
172172- __${name}_debug "ShellCompDirectiveFilterFileExt and ShellCompDirectiveFilterDirs are not supported"
166166+ __${name}_debug "ShellCompDirectiveFilterFileExt ShellCompDirectiveFilterDirs are not supported"
173167174174- # Return here to prevent the completion of the extensions
168168+ # return here to prevent the completion of the extensions
175169 return
176170 }
177171178172 $Values = $Values | Where-Object {
179179- # Filter the result
173173+ # filter the result
180174 $_.Name -like "$WordToComplete*"
181175182176 # Join the flag back if we have an equal sign flag
···186180 }
187181 }
188182189189- # Sort the values in ascending order by name if keep order isn't passed
183183+ # we sort the values in ascending order by name if keep order isn't passed
190184 if (($Directive -band $ShellCompDirectiveKeepOrder) -eq 0 ) {
191185 $Values = $Values | Sort-Object -Property Name
192186 }
···195189 __${name}_debug "ShellCompDirectiveNoFileComp is called"
196190197191 if ($Values.Length -eq 0) {
198198- # Just print an empty string here so the shell does not start to complete paths
199199- # We cannot use CompletionResult here because it does not accept an empty string
192192+ # Just print an empty string here so the
193193+ # shell does not start to complete paths.
194194+ # We cannot use CompletionResult here because
195195+ # it does not accept an empty string as argument.
200196 ""
201197 return
202198 }
203199 }
204200205201 # Get the current mode
206206- $Mode = (Get-PSReadLineKeyHandler | Where-Object {$_.Key -eq "Tab" }).Function
202202+ $Mode = (Get-PSReadLineKeyHandler | Where-Object { $_.Key -eq "Tab" }).Function
207203 __${name}_debug "Mode: $Mode"
208204209205 $Values | ForEach-Object {
210206211211- # Store temporary because switch will overwrite $_
207207+ # store temporary because switch will overwrite $_
212208 $comp = $_
213209214210 # PowerShell supports three different completion modes
215215- # - TabCompleteNext (default Windows style)
211211+ # - TabCompleteNext (default windows style - on each key press the next option is displayed)
216212 # - Complete (works like bash)
217213 # - MenuComplete (works like zsh)
218218- # Set the mode with Set-PSReadLineKeyHandler -Key Tab -Function <mode>
214214+ # You set the mode with Set-PSReadLineKeyHandler -Key Tab -Function <mode>
219215220216 # CompletionResult Arguments:
221221- # 1) CompletionText: text to be used as the auto-completion result
222222- # 2) ListItemText: text to be displayed in the suggestion list
223223- # 3) ResultType: type of completion result
224224- # 4) ToolTip: text for the tooltip with details about the object
217217+ # 1) CompletionText text to be used as the auto completion result
218218+ # 2) ListItemText text to be displayed in the suggestion list
219219+ # 3) ResultType type of completion result
220220+ # 4) ToolTip text for the tooltip with details about the object
225221226222 switch ($Mode) {
227223228228- # Bash-like
224224+ # bash like
229225 "Complete" {
230226231227 if ($Values.Length -eq 1) {
232228 __${name}_debug "Only one completion left"
233229234234- # Insert space after value
230230+ # insert space after value
235231 [System.Management.Automation.CompletionResult]::new($($comp.Name | __${name}_escapeStringWithSpecialChars) + $Space, "$($comp.Name)", 'ParameterValue', "$($comp.Description)")
236232237233 } else {
···251247 }
252248 }
253249254254- # Zsh-like
250250+ # zsh like
255251 "MenuComplete" {
256256- # Insert space after value
257257- # MenuComplete will automatically show the ToolTip
252252+ # insert space after value
253253+ # MenuComplete will automatically show the ToolTip of
254254+ # the highlighted value at the bottom of the suggestions.
258255 [System.Management.Automation.CompletionResult]::new($($comp.Name | __${name}_escapeStringWithSpecialChars) + $Space, "$($comp.Name)", 'ParameterValue', "$($comp.Description)")
259256 }
260257261261- # Default and TabCompleteNext
258258+ # TabCompleteNext and in case we get something unknown
262259 Default {
263263- # Like MenuComplete but without adding a space
264264- # Description will not be shown as it's not possible with TabCompleteNext
260260+ # Like MenuComplete but we don't want to add a space here because
261261+ # the user need to press space anyway to get the completion.
262262+ # Description will not be shown because that's not possible with TabCompleteNext
265263 [System.Management.Automation.CompletionResult]::new($($comp.Name | __${name}_escapeStringWithSpecialChars), "$($comp.Name)", 'ParameterValue', "$($comp.Description)")
266264 }
267265 }
268266269267 }
270268}
271271-272272-$Values | ForEach-Object {
273273- __${name}_debug "Completion suggestion: $($_.Name)"
274274-}
275275-276269277270Register-ArgumentCompleter -CommandName '${name}' -ScriptBlock $__${nameForVar}CompleterBlock
278271`;