Why isn't the function parameter showing in the dialog? - sapui5

The function parameter that is a string isn't showing in the dialog content block. I need to know why and how to make this work. The parameter I am trying to show is string with php code.
I have used MessageToast.show() in my function to view the output string. The output string shows up. I have also tried adding "hello world" string the content block and that works.
Here is my code logic is a string.
logicDialog: function (logic) {
MessageToast.show(logic);
var dialog = new Dialog({
title: 'Boolean Logic',
type: 'Message',
content: new TextArea({
value: logic,
editable: false,
growing: true,
growingMaxLines: 20
}),
beginButton: new Button({
text: 'Close',
press: function () {
dialog.close();
}
}),
afterClose: function () {
dialog.destroy();
}
});
dialog.open();
}
The expected result is dialog that shows the string logic.

Since the example of #TiiJ7 works fine I will just try to throw some possible issues:
-is your Dialog a sap.m.Dialog()?;
-is there any error before the dialog is triggered? (that could somehow stop the functionality of the dialog);
-put a break point in the line of "dialog.close();" to check the content of the string on the scope of the dialog opened;
-is it possible that the string is being manipulated somewhere else and it could a be an issue with concurrency? 1 thread could be changing the value of the string (note that a string is a pointer).
I hope these points could bring you light, since you are the only one with access to the entire code.

Related

Get vscode registerCompletionItemProvider to work in a json file with a `word.` trigger

Update
Thanks to json: use default word pattern issue being resolved, vscode's json language server no longer includes the quotes around a word as part of the word, like "someWord" - now that word would be simply someWord.
In my case, as #rioV8 said, I was not explicitly setting the completionItem.range (because I was just going to use the default range). When you do not set your own range vscode uses the range of the word at the cursor in a completion - which used to include the " and that screwed up my completions.
The starting quote " is part of what VSCode considers the current
"word". Consequently, the completion items you return don't match the
current filter string " and are not displayed.
from Custom Extension for JSON Completion Does Not Work in Double Quotes
To fix that, all I needed to do was to explicity set the range like
item.range = new vscode.Range(position, position);
NOW after the linked fix, since the word no longer includes the " I do not (I tested it) need to explcitly set the range and the default range works fine.
I am using this code to try to register a CompletionProvider in my extension. It is essentially the code from the sample completionProvider sample https://github.com/microsoft/vscode-extension-samples/blob/master/completions-sample/src/extension.ts.
I want it triggered by a . as in "launches." in my extension command in keybindings.json ultimately but it is doing nothing in any json file. Nothing happens, no error.
function activate(context) {
loadLaunchSettings(context);
activeContext = context;
const configCompletionProvider = vscode.languages.registerCompletionItemProvider (
{ language: 'json', scheme: 'file' }, // tried scheme: 'untitled' too
{
// eslint-disable-next-line no-unused-vars
provideCompletionItems(document, position, token, context) {
// get all text until the `position` and check if it reads `"launches."`
const linePrefix = document.lineAt(position).text.substr(0, position.character);
if (!linePrefix.endsWith('\"launches.\"')) { // tried without the escapes too
return undefined;
}
return [
new vscode.CompletionItem('log', vscode.CompletionItemKind.Text),
new vscode.CompletionItem('warn', vscode.CompletionItemKind.Text),
new vscode.CompletionItem('error', vscode.CompletionItemKind.Text),
];
}
},
'.' // trigger
);
context.subscriptions.push(configCompletionProvider);
}
In this code:
{
"key": "alt+f",
"command": "launches." <= provider completion options here
},
I couldn't find anything helpful and thought I followed the sample closely but no completion suggestions either on typing "launches." or using Ctrl+Space to trigger intellisense.
I do have this setting:
"editor.quickSuggestions": {
"comments": true,
"other": true,
"strings": true // <===
},
And I tried various alternatives presented here to a similar problem: Custom Extension for JSON Completion Does Not Work in Double Quotes
Based on the answer by Gamma11 about what is a word in JSON, the whole string is considered a word including the " chars.
It works if you adjust the range the completion item should replace, and not look for the current word at the position.
context.subscriptions.push(vscode.languages.registerCompletionItemProvider (
{ language: 'json', scheme: 'file' },
// 'json',
{
// eslint-disable-next-line no-unused-vars
provideCompletionItems(document, position, token, context) {
// get all text until the `position` and check if it reads `"launches.`
const linePrefix = document.lineAt(position).text.substring(0, position.character);
if (!linePrefix.endsWith('"launches.')) {
return undefined;
}
let myitem = (text) => {
let item = new vscode.CompletionItem(text, vscode.CompletionItemKind.Text);
item.range = new vscode.Range(position, position);
return item;
}
return [
myitem('log'),
myitem('warn'),
myitem('error'),
];
}
},
'.' // trigger
));
Edit:
What also works but does not look nice is
return [
new vscode.CompletionItem('"launches.log"', vscode.CompletionItemKind.Text),
new vscode.CompletionItem('"launches.warn"', vscode.CompletionItemKind.Text),
new vscode.CompletionItem('"launches.error"', vscode.CompletionItemKind.Text),
];
Edit:
Just to supply a completion on any . typed I just removed the test (endsWith) of what was in front of the ..
To see if the completion provider is called I place a LogPoint breakpoint on the return with the CompletionItems.
The documentation of the CompletionItem is very terse.
From the doc of CompletionItem:
It is sufficient to create a completion item from just a label. In that case the completion item will replace the word until the cursor with the given label or insertText. Otherwise the given edit is used.
Although they talk about an edit in the main text, the textEdit doc tells you it is deprecated and you need to use insertText and range. But the additionalTextEdits are not deprecated (??)
The range property is not very clear how an inserting and replacing range are used and what effect you can achieve by setting it a certain way.
When omitted, the range of the current word is used as replace-range and as insert-range the start of the current word to the current position is used.
And then part of the problem is that " is part of a word for JSON files. And as Gamma11 has pointed out if you, for some odd reason, add these "'s to the label it works in some cases. Setting the insertText with the same content does not work, probably because the default range is chosen incorrectly.
If you set the range yourself you bypass the strange default behavior.
Because we want to insert new stuff at the position of the cursor just set range to an empty range at the cursor position.
context.subscriptions.push(vscode.languages.registerCompletionItemProvider (
// { language: 'json', scheme: 'file' },
'json',
{
// eslint-disable-next-line no-unused-vars
provideCompletionItems(document, position, token, context) {
let myitem = (text) => {
let item = new vscode.CompletionItem(text, vscode.CompletionItemKind.Text);
item.range = new vscode.Range(position, position);
return item;
}
return [
myitem('howdy1'),
myitem('howdy2'),
myitem('howdy3'),
];
}
},
'.' // trigger
));

TypeError: Expected container to be an Element, a Document or a DocumentFragment but got string

I'm trying to run the below testcase using RTL , and the test is failing with the error "TypeError: Expected container to be an Element, a Document or a DocumentFragment but got string.". I tried searching for solution but couldn't find one .
describe("Feedback Commponent",()=>{
it('should throw error when feedback textbox is empty', () => {
const { getByLabelText} = render(<Contact />);
fireEvent.change(getByLabelText('Feedback'), {
target: { value: '' },
});
fireEvent.blur(getByLabelText('Feedback'));
debug();
expect(getByTestId('feedback-error')).toBe(
'Please Enter Your Feedback'
);
});
});
The above snippet is suppose to test the feedback form , to be specific only the feedback text box , when it is empty and when user goes out of focus from the textbox ,there should be an error stating "Please Enter Your Feedback".
It seems that you imported getByTestId method straight from testing library instead of destructuring it from render like you did with getByLabelText. getByTestId, according to the docs is:
getByTestId(
// If you're using `screen`, then skip the container argument:
container: HTMLElement,
text: TextMatch,
options?: {
exact?: boolean = true,
normalizer?: NormalizerFn,
}): HTMLElement
So it expects the first argument to be the HTML container, hence the error.
One solution would be to destructure getByTestId as well:
const { getByLabelText, getByTestId } = render(<Contact />);
Another one is to use screen, as suggested by the docs:
import { screen } from '#testing-library/react';
...
expect(screen.getByTestId('feedback-error')).toBe(
'Please Enter Your Feedback'
);
In which case the first 'container' argument is skipped and the string 'feedback-error' is treated like test id 'text' argument. Docs:
https://testing-library.com/docs/queries/bytestid
I resolved the issue by changing the assertion to
expect(getByText('Please Enter Your Feedback')).toBeInTheDocument();
from
expect(getByTestId('feedback-error')).toBe('Please Enter Your Feedback');
Also I noticed that I had setupTest.js file with
import '#testing-library/jest-dom/extend-expect';
missing , which adds custom jest matchers for asserting on DOM nodes, so after adding the above changes my test case passed

How to know what suggestion item is selected in vscode

I complete a vscode extension by vscode.languages.registerCompletionItemProvider(selector, new FuncCompletionProvider(),'.')
I want to listen which suggestion is selected. In the image below,when I click the current item I want to get the CompletionItem Info.
I tried to use the resolveCompletionItem function, but before the suggestion is selected resolveCompletionItem was triggered.
I tried to use the resolveCompletionItem function, but before the suggestion is selected resolveCompletionItem was triggered.
It appears this is intentional. Per their docs:
Note that this function is called when completion items are already showing in the UI or when an item has been selected for insertion
'selected' meaning selected in the list, not committed
The recommended way to gain insight on when a CompletionItem is inserted is using the CompletionProvider#command property:
An optional command that is executed after inserting this completion. Note that additional modifications to the current document should be described with the additionalTextEdits-property.
Example usage:
export function activate(context: vscode.ExtensionContext) {
context.subscriptions.push(
vscode.languages.registerCompletionItemProvider('html', new MyCompletionProvider),
vscode.commands.registerCommand("doTheThing", () => {
console.log('did the thing!!');
});
);
}
class MyCompletionProvider implements vscode.CompletionItemProvider {
provideCompletionItems(document: vscode.TextDocument, position: vscode.Position, token: vscode.CancellationToken, context: vscode.CompletionContext): vscode.ProviderResult<vscode.CompletionItem[] | vscode.CompletionList> {
const myHTMLCompletionItem: vscode.CompletionItem = new vscode.CompletionItem("myHTML");
myHTMLCompletionItem.command = {
title: '',
command: 'doTheThing'
};
return new vscode.CompletionList([myHTMLCompletionItem]);
}
}

Ionic3 Action Sheet with Variable Inputs

I need to create an action sheet or some other kind of alert which displays options to a user and saves the option they clicked in a variable. However, the options displayed to the user need to be retrieved from Firestore and are different for each user (each user also may have a different number of options).
I’ve been able to display these options in an action sheet, but I’m struggling to get the value of the option they clicked.
Below is my code for the function so far. The list of options retrieved from Firestore is saved in an array called ‘options’.
categorizeProblem(){
this.action = this.actionCtrl.create({
title: "What sort of problem did this student have?",
})
this.options.forEach(option => {
var button = {
text: option,
value: //option name
handler: (data)=> {
//Need to get the value/name of the option clicked and save this in a variable
}
}
this.action.addButton(button);
})
this.action.present();
}
I would really appreciate if someone could help me with this or suggest an alternate way to do this.
Thanks in advance!
You can use the text property as your identifier. And then your handler should use the old function syntax so you will have the value of handler's this.
Might sound confusing but here's the code, that should demonstrate my point clearly.
presentActionSheet() {
var self = this;
let options = [
"Option1",
"Option2",
"Option3"
];
let actionSheet = this.actionSheetCtrl.create({
title: 'Categories',
});
options.forEach(option => {
actionSheet.addButton({
text: option,
handler: function() {
self.selectedOption = this.text;
}
})
});
actionSheet.present();
}
Here's the running code.

How to handle click event in Visual Studio Code message box?

According to the API docs, a Message box can take a second argument: an array of strings which act as actions on the message box (which normally just has a single close button/action):
https://code.visualstudio.com/docs/extensionAPI/vscode-api#_window
showInformationMessage(message: string, ...items: string[]): Thenable<string>
So I tried this:
vscode.window.showInformationMessage('hello world', ['test','taco','cheeseburger'], function(value){
console.log(value + " was clicked");
});
But this doesn't seem to work. I get the message box along with a Close button like normal. But then to the left of the close button appears to be another single button with no text or title.
Another function definition is:
showInformationMessage<T extends MessageItem>(message: string, ...items: T[]): Thenable<T>
So I tried something like this:
let message: vscode.MessageItem = { title: 'testing' };
vscode.window.showInformationMessage('hello', [message], function(value){
console.log(value + " was clicked");
});
But that doesn't seem to work either. There is a scarce amount of documentation on this so I cannot figure it out.
vscode.window
.showInformationMessage('hello', 'test', 'taco', 'cheeseburger')
.then(selection => {
console.log(selection);
});
or
vscode.window
.showInformationMessage('hello', ...['test', 'taco', 'cheeseburger'])
.then(selection => {
console.log(selection);
});
Both result in a dialog that looks like this: