How to know what file I am currently in/or editting, in VSCode Extension? - visual-studio-code

I am trying to make a personal website where all of my things are in, but I can't figure out this one, I want to let the website know what file I am looking at in vs-code, It's the same as the Discord RichPrecence extensions, but when I try to read their codes, It's just all scrambled
The extension looks like this ^^^, I just want to know how they did the "Editing [file].js" and "Workspace: [name]"

The code of discord rich presence extension is open source so you can look it up yourself.
Alternatively you can read the vscode API docs, you are probably looking for something like activeTextEditor from which you can get TextDocument property which have a fileName string property.

Related

What is the vscode command to open a file in preview

I wrote an extension for vscode. After installation the extension folder contains documentation in a markdown file. I want to provide a command that loads this file into the preview pane so it displays rendered with images and hyperlinks etc.
You can do this sort of thing interactively:
and I have the full path to the markdown file, so now all I need is details of the command that implements this context menu item.
Web search does not produce complete or usable results.
After cloning the VS Code repo and trawling through the source I discovered the markdown.showPreview and associated commands.
To give credit where due, Lex Li reported the corresponding package.json entry in a comment while I was looking.
Without parameters this previews the content of the active editor, but as I said in a comment, it supports an optional Uri parameter and the code looks like this:
let pathToManual = path.join(context.extensionPath, "manual.md");
let uriManual: vscode.Uri = vscode.Uri.file(pathToManual);
vscode.commands.executeCommand('markdown.showPreview', uriManual);
For information on constructing workspace relative paths see the answer from Mark. The joinPath method he uses requires a base path as a Uri which is conveniently available for the workspace but not for the extension path.
If you need information on things like showing preview to one side then given the dearth of documentation I recommend cloning the repo and searching it for "markdown.showPreview", then exploring nearby code. If you fold the methods it gets easier to survey your options.
Try:
vscode.commands.executeCommand("markdown.showPreview", vscode.Uri.joinPath(vscode.workspace.workspaceFolders[0].uri,'test.md'));
Your fileName there at the end of course. And that assumed you are in the first or only root of a workspace. You might be able to simplify it using:
vscode.Uri.path(<path to file)
instead of the joinPath that I used.

What is the correct way to import/require "vscode" inside the developer tools inside VS Code? [duplicate]

Is there any way to use variable vscode to get editor content just like Atom without writing Extension.
After getting editor content, I can do more things like:
Use Javascript to modify text literally
Custom format
vscode image
atom image
No. This is not supported.
You can use the extension API to extend VS Code. This API lets you get and modify editor contents

How to use variable vscode in Developer tools?

Is there any way to use variable vscode to get editor content just like Atom without writing Extension.
After getting editor content, I can do more things like:
Use Javascript to modify text literally
Custom format
vscode image
atom image
No. This is not supported.
You can use the extension API to extend VS Code. This API lets you get and modify editor contents

VS Code Extension for Loading Source Code

I am interested in extending VS Code to load/edit/save project code, files, etc from a place other than the file system. For example, let's say I wanted to store my project in a database. I have looked at the extension API docs but didn't see anything obvious. Is there an API for extending VS Code in this way?
After some looking around it seems like you need to look at the "Workspace" section of the official API docs:
https://code.visualstudio.com/docs/extensionAPI/vscode-api#_workspace
The rootPath variable takes a string argument, but there's nothing saying that it needs to be a file path so perhaps there's some wiggle room there.
That being said the createFileSystemWatcher() method appears to be set up to work with an actual file system. So even if you can get VSC to find files from somewhere like a database - you probably can't use any of the events that update the UI on changing a file.

MediaWiki bot automatically copying content from external websites

I am trying to find a MediaWiki bot or extension that would do the following:
I sometimes copy external content to MediaWiki to display it in proper context and to make it searchable. That is not very DRY.
I would like to keep a live link to the original content using a special tag and have a bot update the MediaWiki page if the original content changes.
For instance, the snippet could be a configuration file in Subversion that I want to reference in documentation. I would like to do something like:
<external-content
url="http://svn/config.txt"
start="#begin snippet"
end="#end snippet">
</external-content>
The MediaWiki bot would download http://svn/config.txt, retain everything between the #begin snippet and #end snippet comments, and paste the result right between the external-content tags.
This way I can be sure that as I change the config.txt, my MediaWiki documentation stays in sync.
There are numerous other uses. I am not looking only into referencing Subversion content, there are many other web-based systems with data I would like to integrate in this manner.
Does anyone know of a bot that would do this?
You could probably do this with a MediaWiki parser tag extension. In fact, the "Include" extension seems to do something very much like what you're asking for.