I am developing a VSCode extension to generate templates.
However, I cannot figure out how to get the location of the VSCode file that I am currently editing.
When I search for this question, most answers say to do something like vscode.window.activeTextEditor.document.uri.fsPath - however - this gets you the directory for the target VS code window (the Extension Development Host window) - which is not what I want
I want to get the directory of the VS code extension file I am editing (such as the extension.ts file).
Any help greatly appreciated.
If you mean the extension's path:
context.extensionPath
For extension.ts try something like:
context.asAbsolutePath("extension.ts") // if at top level
If you don't know the directory structure of the file you are interested in, like src/otherDirectory/otherSubDirectory, I think you will have to search/walk for it with fs commands starting from the extensionPath. See https://dustinpfister.github.io/2018/07/20/nodejs-ways-to-walk-a-file-system/ for example.
Related
I want to create some extension to VSCode using its Webview feature. I want to show HTML preview as a feature of my extension. As I can see in VSCode API documentation of WebView the paths for resources have to be registered and edit in a special way.
I want to load HTML from the file and then edit and register all paths to CSS and JS into it to create the preview of this one. In my opinion, using some DOM manipulating is the easiest way to create it. Simple import of jsdom doesn't work, even if the same example works in plain Node.js. Have anyone done a similar thing in the way it works well? Maybe there is some other way to solve this problem.
Thank you in advance.
I have done this in the past and the way that it worked was to read that file (with fs in my case) that contains the HTML and render it afterwards. Any resources you want to use have to be passed inside the localResourceRoots array as an option in the vscode.ViewColumn.
Here is a full example:
const panel = vscode.window.createWebviewPanel(
'catCoding',
'Cat Coding',
vscode.ViewColumn.One,
{
// Only allow the webview to access resources in our extension's media directory
localResourceRoots: [vscode.Uri.file(path.join(context.extensionPath, 'media'))]
}
);
I'm working on a file management system built with node.js and electron.
The file management displays a list of files in a folder and allows the user to run custom commands to batch process the files, such as renaming, custom grouping ect...
However I want to implement a feature that if the user clicks on a file it will open with the text editor of their choice.
I can't get the sublime text editor (or any for that matter) to open with node.js code.
I have looked into other questions here on SO such as "Launch an external application from node.js" and "Is it possible to execute an external program from within node.js?" but none of the answers successfully work for me.
Most of the answers open the file with the "default" program of the operating system which is not what I want. I want to be able to choose the program that opens the file.
I found this code below that calls on global path variables to open external software from node:
const exec = require("child_process").exec
exec('yourApp').unref()
But of course it doesn't work if you replace 'yourApp' with a file path pointing to sublime_text.exe like so:
var exec = require('child_process').exec;
exec('C:/Program Files/Sublime Text 3/sublime_text.exe').unref()
Any help would be very very much appreciated. Thank you
You need to use this as your path:
C:/Program\ Files/Sublime\ Text\ 3/sublime_text.exe
I figured it out. It turns out it takes a little bit more code than I first posted to open an external file. The full code looks like this:
// Create a child process
var spawn = require('child_process').spawn;
var child = spawn('Path_To_.exe', ['parameters', 'Path_To_File']);
Also just in case anyone is wondering it was not necessary to escape sequence the spaces within the file name.
Thank you for everyone who offered to help!
I've been looking at the atom-beautify site and example .jsbeauifyrc, .editorconfig, and uncrustify.cgf files.
I've also reviewed the options for atom-beautify. I know I'm supposed to specify where the config file is located in the atom-beautify settings. I've tried putting a .jsbeautifyrc file, an uncrustify.cfg file, and both files in the same directory I specify in the atom-beautify settings. It doesn't have any effect. The default settings are used. I'd like to make some old C++ code look more uniform for my current project and future projects my group is working on.
Which file am I supposed to use?
What must I include in each file?
Where should this/these file(s) be located?
How do I specify the path?
Are there any other changes I need to make that I'm not aware of?
To sum up, I want to use uncrustify from within the Atom editor (using the atom-beautify package) to make my C++ code look nice.
Make sure uncrustify is installed on your computer, and accessible from CLI
In the settings for atom-beautify, go under the C++ section and type uncrustify.cfg as a Config Path
Place the config file name uncrustify.cfg in the root folder
Try beautifying your code, it should be using your config file now
you have to add PathVariable of uncrustify.exe (From Source AtomBeatify : https://atom.io/packages/atom-beautify ) on your system , when you upload you code to Atom click on ALT+CTRL+B it will beautify you Code .
Download zip On Windows, download the latest version of Uncrustify here: https://sourceforge.net/projects/uncrustify/files/latest/download
Extract zip The program is a standalone exe, so just extract the downloaded uncrustify-...-win32.zip file anywhere. For this example, I'll use C:\Uncrustify. So, the uncrustify.exe would be in that directory.
Add directory to PATH System Environment Variable In Windows 7+: Type Winkey + env - Select "Edit the system environment variables"
On the Advanced tab, click the Environment Variables button at the bottom. In the System variables section at the bottom, click the Path variable, then click the Edit... button.
Click the New button, and type C:\Uncrustify, or the directory that you extracted uncrustify.exe to.
Important: Click OK to close the dialog boxes or your change will not save. Verify
In a CMD window, typing where uncrustify should return the path to the uncrustify.exe.
In my case it shows C:\Uncrustify\uncrustify.exe Close Atom and reopen it. Now you should be able to atom-beautify and it will use Uncrustify to format your selection
So i am making a mobile app. in this app, on my main screen, i have a button that when clicked it will load another frame, or js file. this i know how to do but when pressing the button it gives me an error, "cant find file". after 3 hours of web searching i have tried changing the path names to every possible combination and moveing the file around. after doing so i came to realize that next to the new file i created, or any new file i create, there is an "*" and a question mark. for example if i make a new file called login.js it will show up on the explorer window as *?login.js, where the question mark is much smaller symbol. Is there a manifest i must add it to, like in netbeans, because it seems as if there is an error in the file but it is empty.
function signup(e){
var menu = Ti.UI.createWindow({
url: 'Main-Menu.js'
});
menu.open();
}
i also did: Titanium.include('/controllers/Main-Menu.js');
but always getting the same error, the JS file is in my apps controller folder.
This *? indication comes from the git plugin that is shipped with Titanium Studio. It indicates that the file is not commited.
To answer your "can't find file" - question, I need to know some more details about your environment (target platform, sdk version, example code, ...)
Short version: can you help me fill in this code?
var conkeror_settings_dir = ".conkeror.mozdev.org/settings";
function load_all_js_files_in_dir (dir) {
var full_path = get_home_directory().appendRelativePath(dir);
// YOUR CODE HERE
}
load_all_js_files_in_dir(conkeror_settings_dir);
Background
I'm trying out Conkeror for web browsing. It's an emacs-like browser running on Mozilla's rendering engine, using javascript as configuration language (filling the role that elisp plays for emacs). In my emacs config, I have split my customizations into a series of files, where each file is a single unit of related options (for example, all my perl-related settings might be in perl-settings.el. All these settings files are loaded automatically by a function in my .emacs that simply loads every elisp file under my "settings" directory.
I am looking to structure my Conkeror config in the same way, with my main conkeror-rc file basically being a stub that loads all the js files under a certain directory relative to my home directory. Unfortunately, I am much less literate in javascript than I am in elisp, so I don't even know how to "source" a file.
I found a suitable answer, though it isn't really what I was looking for. If you set your conkerorrc file to a directory, then all the js files in that dir will be loaded.