When implementing a "onReferences" with visual-studio-language-server, how do I search through the content of the files in the workspace? - visual-studio-code

I'm currently implementing onReferences on the server side of a language server. When a user right clicks on some custom syntax in a markdown file, I want to be able to use that syntax to search for other occurances of strings elsewhere in the workspace.
connection.onReferences((params) => {
// I can get the syntax here from the client through params and the document manager
// but I only have access to the document manager and the open documents.
// I want to be able to return a location from a possibly unopened file elsewhere
return null;
});
Since I know this happens all the time with the ts-server (click on an interface name and find all occurances) I know this is surely possible. What general strategy am I missing that I can obtain locations of strings elsewhere?

Related

Word addin, set filename

If one starts a blank file on Word you can usually see in the top bar a name such as "Document1", "Document2" and so on.
Yet, if you attempt to open a file using the Word JS API like this:
Word.run((context) => {
context.application.createDocument(documentB64).open()
return context.sync()
})
The top bar comes out like this:
No filename is set.
To set a filename/handle(?), I tried using the code given here Office JS - Add customProperty to new document but that didn't help.
My addin is usually used in conjunction with another (VSTO) add-on and that add-on can't work properly with the documents opened by my addin and I believe the lack of a filename (/handle?) explains it to some extent.
Is there something I can do about this?
Thank you
Currently you can't do this because the newly created document is just a temporary file and not saved. can you try to call the following code to make sure the newly created file is saved?
const documentCreated = context.application.createDocument(externalDoc);
documentCreated.save();
documentCreated.open();

How to avoid opening a QuickInput when choosing files to compare in a vscode extension?

In my case I want to compare two files.
But I don't want the user to select the File in the QuickInput form, i want to choose this directly for him.
vscode.commands.executeCommand("workbench.files.action.compareFileWith", filePath)
This results in
Meaning that filePath is ignored and a QuickInput is displayed instead.
Is there a way to directly select a file programmatically instead of showing the QuickInput first?
While the compareFileWith command probably requires a QuickInput panel to use, you can use the other compare commands to do what you want:
// using the current file for the 'compareWith' file
const currentFileUri = vscode.window.activeTextEditor.document.uri;
// create a Uri from some filePath
const compareWithSelectedUri = vscode.Uri.file('C:\\Users\\Mark\\OneDrive\\Test Bed\\BAR.txt');
await vscode.commands.executeCommand('selectForCompare', currentFileUri)
await vscode.commands.executeCommand('compareFiles', compareWithSelectedUri);
This works in my testing.
Looking at compareFileWith in https://github.com/microsoft/vscode/blob/9b9361cfd1b0678f0bb0b32bf9925b6520bb9926/src/vs/workbench/contrib/files/browser/fileActions.ts I don't think there is any way to avoid the QuickInput opening.
Alternatively, what you are asking for would be "easy" if an open method were supported on TabGroups api like the close methods. You would create a tab of kind TabInputTextDiff with an original uri and a modifieed uri.
When the TabGroups api was being developed there was an open tab method but it was removed prior to release and hasn't seen any love since. See https://github.com/microsoft/vscode/commit/aa69f3d7623c464aba726d12ea0d83428f43e8b9#commitcomment-71831337.
I'll open an issue to see if it will help (and post the link here later).

VSCode Extension: Add document metadata when opening file

I am building an extension that will open files from a remote server, but need to add some metadata into each document opened, which I will use later when the document is saved/closed.
Is there a way I can insert metadata into each document?
vscode.workspace.openTextDocument(filePath + fileName).then(doc => {
// Add some document specific metadata
vscode.window.showTextDocument(doc);
});
I understand that VSC does that, for example storing the caret and scroll positions, or selection if any, and so on, retrieving it when you reopen the file.
I believe it does that by storing data outside of the files, otherwise it would alter their data, or it would need to manipulate metadata according to the local system (Windows, macOS, Linux, etc.), which is not obvious, if even possible.
On Windows, in C:\Users<user name>\AppData\Roaming\Code, there are a number of databases which might fit this purpose, you can do a similar thing.

Can OpenXML be used to launch a new Word instance?

I'm able to generate Word documents without issue. I save the resulting *.docx file to a temporary location and then need to launch the file in Word.
The requirement is to not "open" the file in Word (easily done with a Process.Start) but to have load into Word as a new unsaved file. This is because certain propriety integrations for Word need to take over when a user saves the file and don't kick in if the file is ready saved but to a location on disk.
I've achieved this by using Interop calls to the Word application, adding the new document to Word's workspace. My problem is with Interop which tends to break on various client machines, particularly when Office upgrades take place (say a client had 32-bit office but upgraded with a 64-bit version).
I'm somewhat new to OpenXML, but can it be used to automate Word or is Interop my only real option?
object oFilename = tmpFileName;
object oNewTemplate = false;
object oDocumentType = 0;
object oVisible = true;
Document document = _application.Documents.Add(ref oFilename, ref oNewTemplate, ref oDocumentType, ref oVisible);
No, the Open XML technology has no way of interacting with the Office (Word) application - it's for file creation/manipulation, only. The interop is required in order to do anything with the Word application.
There is sort of a way around this - and it's only possible with Word, no other Office application has this - is to convert the Open XML content to the OPC flat-file format. This "concatenates" the various packages that make up the zip file to a pure text string, essetially a single XML file.
XML content in the OPC flat-file format can then be written to an already opened (even newly created) Word document using the Range.InsertXML method via "the interop". In a way, this "streams" the Open XML content into the opened Word document.
The problem with this approach is that certain document-level properties are not written to the target document, so not all aspects of the opened document can be changed. For example: page size, orientation, headers, footers... So if this kind of thing also needs to be affected the interop is required for such settings.

What does the parameter "cvid" in Bing search engine stands for?

As I searching something with Bing and I open the Chrome development tools. Here is the request url:
http://cn.bing.com/search?q=%e4%b9%a0%e8%bf%91%e5%b9%b3&go=%e6%8f%90%e4%ba%a4&qs=n&pq=%e4%b9%a0%e8%bf%91%e5%b9%b3&sc=6-6&sp=-1&sk=&cvid=AF49B4165317411D8AFEF30F13BCD108&first=10&FORM=PERE
So, what does the parameter "cvid" stands for? It seems if i don't set a cvid,i can't get the complete result html in my program.
By the way, the cvid is calculated by the browser automaticlly, so how to calculate?
In the Bing search context, cvid represents the JavaScript parameter ConversationId. Bing uses this key to identify your search result collection as its reply to your query, q. Similarly, pq is PartialQuery. These and other parameters may also apply to different kinds of searches, such as image or video searches.
Next, qs is your query's SuggestionType, sc shows your SuggestionCount, and from the suggestion list (dropped down, if enabled), sp shows the SuggestionPosition you chose. In your case, you did not select a suggestion, so &sp=-1. Toward the end of your string, sk is the SkipValue, because you might skip through your result pages, first tells the issuer how many results belong on the first page, and I'll let you figure out what FORM means. ;)
TRY:
Navigate to Bing, conduct a search, choose some options, change your displays, and change some search types. Next, open file explorer and navigate to your Windows OS equivalent of the following path.
C:\Users\{user}\AppData\Local\Microsoft\Windows
Next, you may need to adjust your View temporarily to "Show hidden files, folders, and drives." View tab > Options > Change... > View tab again, and click the bullet to "Show...".
In File Explorer's Search pane at the upper right, enter *.js to find all JavaScript files. It may point you several subfolders deeper, and the folder names may be hashed. Choose a JavaScript file you find interesting, right-click the file, and open it with Notepad, your favorite IDE, or some similar editor. You should see something akin to this (truncated; may not run independently):
var AutoSuggest,__extends,Bing,sa_inst;(function(n){var t;(function(n){var t,i,r,u,f,e;(function(n){n.User="SRCHHPGUSR"})(t=n.CookieNames||(n.CookieNames={})),function(n){n.AutoSuggest="AS"}(i=n.CrumbNames||(n.CrumbNames={})),function(n){n.CursorPosition="cp";n.ConversationId="cvid";n.SuggestionCount="sc";n.PartialQuery="pq";n.SuggestionPosition="sp";n.SuggestionType="qs";n.PreviewPaneSuggestionType="qsc";n.SkipValue="sk";n.PreviewPaneSkipValue="skc";n.Ghosting="ghc";n.Css="css";n.Count="count";n.DataSet="ds";n.SessionId="sid";n.TimeStamp="qt";n.Query="q";n.ImpressionGuid="ig";n.QFQuery="qry";n.BaseQuery="bq";n.FormCode="form";n.HashedMuid="nclid";n.RequestElToken="elvr";n.ElTokenValue="elv";n.AppId="appid";n.History="history";n.NoHistory="nohs";n.ApiTextDecoration="textdecorations";n.ClientId="clientid";n.Market="mkt";n.Scope="scope";n.CountryCode="cc";n.HomeGeographicRegion="hgr";n.SetLang="setlang";n.ZeroInputSerp="zis"}(r=n.QueryParams||(n.QueryParams={}))
I hope that helps someone! :D
I'm also trying to find out what this is :)
I'm pretty sure it's an encryption mechanism for bing a la public key cryptography, though I could be wildly wrong. There is another field called pq - and p's and q's are used a lot in crypto theory.
The field is 32 nibbles (e.g. 8D0E519A91024A08B075654D006C0A14) which equals 128 bits. This number results in some arithmetic operation with the binary value of your search and bing's private key - thus making url generation quite difficult.