How to check if the text in an editor has focus when developing an extension? - visual-studio-code

Same to editorTextFocus, but I want to check this condition when developing an extension, what's the API for that?
I've tried the following:
if (window.activeTextEditor) {
// ...
}
But the result is not the same as using editorTextFocus.

So I've wanted something like a getContext API which is the corollary to setContext API, in this case, I would use it like getContext('editorTextFocus').
After a lot of searchings, I ended up in this Add getContext command PR, but it got rejected due to these reasons, basically saying getContext API is not the solution for this type of issues. I guess we'll have to wait until the VSCode team come up with a better API for this, let's hope it won't take too long.

Related

How to show message from custom function w/o using task pane or return value?

Is it possible to show a message (just a warning the user can dismiss) from code in a custom function without using a task pane? (And without making it the return value of the function.) Something that shows up in the status bar, or a popup, etc.?
And obviously, if so, how do you do it?
(Office.context.ui.displayDialogAsync isn't available from the custom functions context, not even in the shared runtime.)
Thank you for reaching us. So far we don't support it. I'd recommend going to Microsoft 365 Developer Platform Ideas Forum and see if this feature has already been requested or if request a new feature. Thanks for your support!

Create new work item type using VSTS Extension

Based on the documentation https://learn.microsoft.com/en-us/vsts/extend/overview?view=vsts#what-makes-up-an-extension, a VSTS extension can be used to extend the work item form.
However, I would like my extension to automatically create a new work item type once it is installed. Is this something that is possible? I can't find any documentation online that suggests how to do it.
Theoretically this is possible, the extension has a "first load" call which you can use to use the rest api to create a custom process or update the existing custom process. The REST Api to change processes isn't public yet, so you'll have to work from using fiddler to watch how the web ui does it.
Due to the way processes are linked to projects, all projects with that process will get the new work item type.
I could not find a lot of documentation online for this, but the VSS web extensions SDK(https://www.npmjs.com/package/vss-web-extension-sdk) has a REST client called 'ProcessDefinitionsRestClient' declared in the typings/tfs.d.ts file. This client has a createWorkItemType method available that looks like this:
createWorkItemType(workItemType: ProcessDefinitionsContracts.WorkItemTypeModel, processId: string): IPromise<ProcessDefinitionsContracts.WorkItemTypeModel>;.
The 'ProcessRestClient' client has methods to create a new/inherited process to which the new WIT can be added.
I have not tried it out yet, and these APIs are still in preview, but maybe they can get you started on the right path.

Deploying actions on google webhook on glitch

I want to deploy this example on glitch. I've added package.js and index.js to my glitch project and built successfully.
However, the code is missing a section to listen for HTTPS requests. In most node.js/express webapps, there is code to indicate which paths trigger which functions, but this is missing from the example. Can you explain to me how it should work and why that part is missing from this example?
It's not clear what do you mean by "the code is missing a section to listen" as the only main feature of index.js is to listen to requests and return information.
I suggest you check index.js and make sure that you getting requests to your end point on glitch.
Also, it would be helpful if you can share your glitch project over here at SO so we could see what you are doing.
Btw, you might want to double check that you have all the packages
I also created this simple example on Glitch - It's returning the current bitcoin price. Feel free to remix it and use the code there for your own action.
Good luck!
The part that "listens to requests" is
// The Entry point to all our actions
const actionMap = new Map();
actionMap.set(ACTION_PRICE, priceHandler);
actionMap.set(ACTION_TOTAL, totalHandler);
actionMap.set(ACTION_BLOCK, blockCountHandler);
actionMap.set(ACTION_MARKET, marketCaptHandler);
actionMap.set(ACTION_INTERVAL, intervalHandler);
assistant.handleRequest(actionMap);
where each ACTION is an action(in an intent) in Dialogflow and the handler is the corresponding function in your code.
I'd recommend you take a look at
https://codelabs.developers.google.com/codelabs/assistant-codelab/index.html?index=..%2F..%2Findex#0
If you want a good example of an assistant app, though this uses firebase instead of glitch.

Sentry Raven inside Firefox Addon SDK

I am making a Firefox Extension and I want to log the errors/messages/exceptions produced by the extension code using Sentry.
I tried the JavsScript Raven client but I guess its not really made to live inside the "Content" context.
The error I get is: message = "debug" is read-only, but my actual question is, how do I go about integrating Sentry in a Firefox Addon?
PS: No, this wont go into general distribution, my api keys are safe.
What I did was just to omit calling .install() and just use the error/message reporting.
There will be no automatic catching and source code but it works for my purposes.

Automatic handling of errors/warnings

On a linking error, I can raise appropriate diagnostic (say MyDSL.MY_APPROPRIATE_DIAGNOSTIC) and then write, in MyDSLQuickfixProvider, a quick fix for it by annotating it in this way:
#Fix(MyDSL.MY_APPROPRIATE_DIAGNOSTIC)
public void fixMyAppropriateDiagnostic(final Issue issue, final IssueResolutionAcceptor acceptor) {
...
}
What about if I wanted to automatically resolve a diagnostic, i.e. automatically execute an IModification without propose it to the user as quick fix (imagine the quick fix for the diagnostic is unique)?
Is there a way to associate a (immediate) handling code to a diagnostic in a similar manner to what happens for (user-proposed) quick fixes?
Thanks in advance,
Marco
There is no way to set a quick fix to be executed automatically. Your alternatives are:
Invoke the marker resolution code from somewhere else in your code. I.e. while marker resolutions are typically triggered explicitly on user request using the problems view, ruler buttons and similar UI, you could invoke them from anywhere. Be sure that you don't interfere with quickfixes, which are not from your plugin and make sure your users are not surprised by this non-eclipse workflow.
For some issues you may be able to instead create code completion rules or templates. Those are still not fully automatic as requested, but basically you can already "correct" partial user input that way and avoid flagging a violation for the complete input.