How to put a message in VS Code Problems window - visual-studio-code

I have a VS Code extension which enforces a json schema onto a json file. When there is an error, it posts a message into the Problems window which is great.
How can I write to this window, from my extension, to put my own messages in the Problems window?
I have searched the docs, and could only find showInformationMessage, showErrorMessage and showWarningMessage but none of these put the message anywhere visible that I can see.
Any hints to the correct method or a suitable doc page would be most helpful.

You can use diagnostics for this. The starting point for that API is createDiagnosticCollection() from the vscode.languages namespace. vscode-extension-samples has a simple example for this. The basic idea is that DiagnosticCollection acts as a map with URIs as keys and arrays of diagnostics as values.

Related

Opening the VSC settings window from code

I'm working on a Visual Studio Code extension, where some settings are required for it to work properly. Right now, in case the user has forgotten something, I'm showing a warning message indicating this, and telling them to fix this property in the settings. I would, however, like to add a button that opens the settings page of that property.
However, after looking around for over an hour, I can't seem to find any support for this in the Api, or anyone else asking this question (which I find a bit weird?). If it really doesn't exist, I'd still expect at least 1 other person asking this somewhere, but as far as I can see there's absolutely nothing.
Is it possible to open the settings window (preferably even filtering them down to only my extension's properties/the one property that has to be filled in) from code?
Thanks in advance
I found it out myself after digging through the keybinds window. You can use the following to open the settings:
vscode.commands.executeCommand("workbench.action.openSettings2");
I did not, however, find how to pass a search query into it to open a specific place in the settings.
EDIT: You can use openSettings & add the search query as an extra argument to executeCommand. For example - if your property is defined as my.extension.property in package.json, you can use this:
vscode.commands.executeCommand("workbench.action.openSettings", "my.extension.property");

Get all problems (errors, warnings, etc.) using VSCode extensions API

I am creating a VSCode extension and I need a way to access all of the current errors, warnings, etc in the Problems pane but I am not even sure if the API provides access to this. I see that I can create Diagnostics and it appears that I can get those diagnostics with the DiagnosticCollection but I don't see where I can get a list of all of the errors and such. Does anyone have experience with this.
p.s. I have tried
console.log(vscode.DiagnosticCollection) // undefined
console.log(vscode) // Looked through the object and found nothing of use
console.log(window) // Same thing. Nothing of use.
According to the documentation seems like it's not possible at the moment.
but I saw some discussions on adding an API to the problem view so that might be available in one of the next versions.
There are now 2 api's for this, see api reference: language diagnostics:
getDiagnostics(): [Uri, Diagnostic[]][] get diagnostics for all files
let diagnostics = vscode.languages.getDiagnostics();
getDiagnostics(resource: Uri): Diagnostic[] get the diagnostics for a specific uri
const uri = vscode.window.activeTextEditor.document.uri;
let diagnostics = vscode.languages.getDiagnostics(uri); // returns an array

RxBluetoothKit documentation?

I'm trying out RxBluetoothKit and one of the bullet point features is "Documentation", but the link for that leads to a page which is just a copy of the README with a sidebar saying "Error Parsing Pod Could not find Objective-C Classes."
The README is quite detailed, and the sample code is useful, but an API reference would be nice for the more tricky details. For example, the README has an example with this code:
peripheral.connect()
.flatMap { $0.discoverServices([serviceId]) }
I have no idea what type serviceId is - I presume it's not a string.
All of the documentation is written above the methods so while typing discoverServices in Xcode you should be able to click on method with options key and little popup will come up with formatted documentation. Our doc is formatted by the CocoaDocs - it appears that it has some problems. I'm working on fixing it - here you can find the issue Github issue
And here you could find proper link to documentation: RxBluetoothKit documentation

Eclipse builder: How does it work?

Does anyone know any details on the underlying eclipse builder that sends jobs to the compiler and get its report? and how to tap to it? The level of abstraction that the builder extension offers is too high and the information insufficient. So I implemented an IResourceChangeListener and played with the ResourceDelta in order to get the messages from an IMarker. It works perfectly, however I realized the message is just returning a string. So my question is, how do I do in order to get the type/reference of the object where the error is, what type of error, what class it should belongs to and all available info.
Thanks.
Have you looked at the builder documentation?
And there is also This article by John.
I think between those two and looking at the code you will find everything you need to know.

How to read message from console tab view in eclipse plugin development

requirement is to read message from IConsoleConstants.ID_CONSOLE_VIEW and write it into text file.
Say myConsole (of type MessageConsole) is the reference to your console. The below code will give you the required.
myConsole.getDocument().get();
I don't think you will be able to retreive a direct stream to read the console content. Note also that the console view may have multiple different consoles, you will have to retrieve the good one.
Retrieving the content displayed in a single console should be possible going through the IDocument of a TextConsole. You can get the whole text content. You could also have a look to the IDocumentListener if you can be notified of changes.
Another solution should be to go with a PatternMatchListener of the TextConsole directly.
Anyway I don't think there is a direct solution to do this with the Eclipse console API.