How to support powershell tab expansion in psprovider? - powershell

I'm implementing Powershell PSProvider for some internal hierarchical data. Everything works fine, I can navigate through the tree with usual cd/dir commands, the only thing doesn't work is tab completion.
What I can see is that Powershell calls function GetChildName() with an asterisk in the path when Tab is pressed (if I type "dir c" and press Tab, GetChildName() function will be called with string "c*", several times). I tried to return all child names from the folder that begins with "c", but Powershell always displays just the first child name in the front. I can't find any documentation about this behavior, what I'm missing?

Are you sure you aren't just seeing normal behavior? With the default Tab Expansion, you will only see the first result. Pressing tab additional times will cycle through the list of returned results from the provider.
There are some quirks with providers. I have been working on one using the Script Provider project. I put debug code in all my methods to see which ones PowerShell was calling, when, and with what arguments.

I found where's the problem - function GetChildName() in the provider shouldn't try to expand given file name if asterisk is part of the name; The function should return child name if it can find an exact match, or call base.GetChildName() in any other case. Something like this:
protected override string GetChildName(string path) {
string name = SomeFunctionThatTriesToFindExactMatchForGivenPath(path);
if(string.IsNullOrEmpty( ret ) )
ret = base.GetChildName( path );
return ret;
}
BTW, I found that default tab expansion is very forgiving about stuff that can be returned from GetChildName() function - even if return value have slash/backslash in the front/back, tab expansion will work. But PowerTab, popular tab expansion module, is much more picky about return values.

Related

VsCode Extension custom CompletionItem disables built-in Intellisense

I am working on a VsCode extension in that I want to provide custom snippets for code completion.
I know about the option of using snippet json files directly, however those have the limitation of not being able to utilize the CompletionItemKind property that determines the icon next to the completion suggestion in the pop-up.
My issue:
If I implement a simple CompletionItemProvider like this:
context.subscriptions.push(
vscode.languages.registerCompletionItemProvider(
{scheme:"file",language:"MyLang"},
{
provideCompletionItems(document: vscode.TextDocument, position: vscode.Position) {
let item = new vscode.CompletionItem('test');
item.documentation = 'my test function';
item.kind = vscode.CompletionItemKind.Function;
return [item];
}
}
)
)
then the original VsCode IntelliSense text suggestions are not shown anymore, only my own. Should I just return a kind of an empty response, like
provideCompletionItems(document: vscode.TextDocument, position: vscode.Position) {
return [null|[]|undefined];
}
the suggestions appear again as they should. It seems to me that instead of merging the results of the built-in IntelliSense and my own provider, the built-in ones get simply overridden.
Question:
How can I keep the built-in IntelliSense suggestions while applying my own CompletionItems?
VsCode Version: v1.68.1 Ubuntu
I seem to have found the answer for my problem, so I will answer my question.
Multiple providers can be registered for a language. In that case providers are sorted
by their {#link languages.match score} and groups of equal score are sequentially asked for
completion items. The process stops when one or many providers of a group return a
result.
My provider seems to provide results that are just higher scored than those of IntelliSense.
Since I didn't provide any trigger characters, my CompletionItems were comteping directly with the words found by the built-in system by every single pressed key and won.My solution is to simply parse and register the words in my TextDocument myself and extend my provider results by them. I could probably just as well create and register a new CompletionItemProvider for them if I wanted to, however I decided to have a different structure for my project.

VS Code Extension: TreeItem command property how to issue vscode.open

I'd like to open a file when my treeView items are clicked (similar to how the default explorer opens a file). However, I'm stuck on implementing this feature. From my understanding, one way to implement this is to define the command property of the TreeItem type, as seen here. This link also says:
Please use vscode.open or vscode.diff as command IDs when the tree item is opening something in the editor. Using these commands ensures that the resulting editor will appear consistent with how other built-in trees open editors.
As seen here, vscode.open takes in some arguments, in particular it needs a uri of a text document. I'm very confused at how to pass that argument to this command in this manner. I tried:
class MyTreeItem extends TreeItem {
children: FunctionsTreeItem[]|undefined;
constructor(label: string, filePath: string, children?: FunctionsTreeItem[]) {
super(
label,
children === undefined ? TreeItemCollapsibleState.None :
TreeItemCollapsibleState.Expanded);
this.children = children;
this.command = {
title: "",
command: "vscode.open",
arguments: [{"uri": filePath}]
}
or with the arguments line modified to just [filePath]. Neither works. I'm not sure how to approach this.
I finally found an example from one of their issues. The code here gives a very good example.
So, the syntax is just this:
arguments: [Uri.file(filePath)]

How to moving fields in forms of ncurses

I've written a program in C using ncurses and specially forms. I need that a particular field of my form moves as I'm filling the form. I tried move_field, but it doesn't work.
Here is how I wrote it :
if (typact==ADSD && rowc>rowg )
{
move_field(field[ietg],rowg=rowc,colg);
refresh();
}
I'm sure that the move_field is executed (I use xCode for debugging my program). I presume that refresh is not sufficient. I tried also placing move_field between unpost_form and post_form like this:
if (typact==ADSD && rowc>rowg /* && !field_status(field[ietg]) */ )
{ unpost_form(my_form);
move_field(field[ietg],rowg=rowc,colg);
post_form(my_form); refresh();
}
but it doesn't work once again. The form is erased and re-posted without the texts I have written and the field is always in the same place.
How could I use move_field?
The manual page says
The function move_field moves the given field (which must be disconnected) to a specified location on the screen.
You can disconnect a field by retrieving the current list of fields with form_fields (and its length using field_count), removing the field from that list and updating the list using set_form_fields.
When using move_field, you must also (temporarily) unpost the form with unpost_form. Otherwise, move_field returns E_POSTED (The form is already posted). After moving the field, use post_form to get the form-driver to work with the updated form.
The test/move_field.c file in ncurses sources provides an example of these calls.

How to clear method call parameters/arguments filled by SublimeText Jedi-autocomplete?

I am testing out SublimeText auto-complete using JEDI package and one problem I am having is unrequired parameters are auto-filling function/method calls:
For example in Flask:
I can just call the function as such:
app.run(),
but JEDI-Autocomplete is doing something like this:
app.run(host= , port=..., debug=..., load_dotenv=...)
I can't figure out how to clear the parameters as it's not needed in this case.
Same problem with:
app = Flask(__name__)
Instead autocomplete is automatically filling in unrequired parameters and seemingly forcing me to add value to each argument.
Searching the Sublime Text 3's SublimeJEDI repo (issue #290 - open() autocompletes all args when in required mode) seems to suggests that there's an option to control autocomplete aggressiveness:
"auto_complete_function_params": "all",
In your preference settings (either user preferences or syntax preferences).
From their README.md:
Function parameters completion has 3 different behaviors:
Insert all function arguments on autocomplete:
# complete result
func(a, b, c, d=True, e=1, f=None)
# sublime_jedi.sublime-settings
{
"auto_complete_function_params": "all"
}
Insert only required arguments that don't have default value (default behavior):
# complete result
func(a, b, c)
# sublime_jedi.sublime-settings
{
"auto_complete_function_params": "required"
}
Do not insert any arguments:
# complete result
func()
# sublime_jedi.sublime-settings
{
"auto_complete_function_params": ""
}
More info about auto_complete_function_params
You may experiment with those options to see what fits you better.
Turning auto_complete off and using SublimeJedi: ShowDocstring (defaults to Ctrl+Alt+D) when the cursor is after the function name fixes the issue for me.
You can also hover over the function name or use SublimeJedi: Show Signature.

install4j: how can i pass command line arguments to windows service

I've created a windows service using install4j and everything works but now I need to pass it command line arguments to the service. I know I can configure them at service creation time in the new service wizard but i was hoping to either pass the arguments to the register service command ie:
myservice.exe --install --arg arg1=val1 --arg arg1=val2 "My Service Name1"
or by putting them in the .vmoptions file like:
-Xmx256m
arg1=val1
arg2=val2
It seems like the only way to do this is to modify my code to pick up the service name via exe4j.launchName and then load some other file or environment variables that has the necessary configuration for that particular service. I've used other service creation tools for java in the past and they all had straightforward support for command line arguments registered by the user.
I know you asked this back in January, but did you ever figure this out?
I don't know where you're sourcing val1, val2 etc from. Are they entered by the user into fields in a form in the installation process? Assuming they are, then this is a similar problem to one I faced a while back.
My approach for this was to have a Configurable Form with the necessary fields (as Text Field objects), and obviously have variables assigned to the values of the text fields (under the 'User Input/Variable Name' category of the text field).
Later in the installation process I had a Display Progress screen with a Run Script action attached to it with some java to achieve what I wanted to do.
There are two 'gotchas' when optionally setting variables in install4j this way. Firstly, the variable HAS to be set no matter what, even if it's just to the empty string. So, if the user leaves a field blank (ie they don't want to pass that argument into the service), you'll still need to provide an empty string to the Run executable or Launch Service task (more in that in a moment) Secondly, arguments can't have spaces - every space-separated argument has to have its own line.
With that in mind, here's a Run script code snippet that might achieve what you want:
final String[] argumentNames = {"arg1", "arg2", "arg3"};
// For each argument this method creates two variables. For example for arg1 it creates
// arg1ArgumentIdentifierOptional and arg1ArgumentAssignmentOptional.
// If the value of the variable set from the previous form (in this case, arg1) is not empty, then it will
// set 'arg1ArgumentIdentifierOptional' to '--arg', and 'arg1ArgumentAssignmentOptional' to the string arg1=val1 (where val1
// was the value the user entered in the form for the variable).
// Otherwise, both arg1ArgumentIdentifierOptional and arg1ArgumentAssignmentOptional will be set to empty.
//
// This allows the installer to pass both parameters in a later Run executable task without worrying about if they're
// set or not.
for (String argumentName : argumentNames) {
String argumentValue = context.getVariable(argumentName)==null?null:context.getVariable(argumentName)+"";
boolean valueNonEmpty = (argumentValue != null && argumentValue.length() > 0);
context.setVariable(
argumentName + "ArgumentIdentifierOptional",
valueNonEmpty ? "--arg": ""
);
context.setVariable(
argumentName + "ArgumentAssignmentOptional",
valueNonEmpty ? argumentName+"="+argumentValue : ""
);
}
return true;
The final step is to launch the service or executable. I'm not too sure how services work, but with the executable, you create the task then edit the 'Arguments' field, giving it a line-separated list of values.
So in your case, it might look like this:
--install
${installer:arg1ArgumentIdentifierOptional}
${installer:arg1ArgumentAssignmentOptional}
${installer:arg2ArgumentIdentifierOptional}
${installer:arg2ArgumentAssignmentOptional}
${installer:arg3ArgumentIdentifierOptional}
${installer:arg3ArgumentAssignmentOptional}
"My Service Name1"
And that's it. If anyone else knows how to do this better feel free to improve on this method (this is for install4j 4.2.8, btw).