Can I get the list of the available scopes for snippets?
Is there any native functionality that would control what files to create and where?
Snippets are scoped to languages and introduced to VS Code as global or local to a workspace. Languages can be contributed to VS Code by exceptions. Typically by declaring a language in the package.json, adding a syntax and snippet files. Update:
Here is the guide how to add a snippet to any language via your extension. If you follow the guide and add a snippet to the current workspace, you will notice that the file with extension .code-snippets gets created under the .vscode folder in the workspace. Therefore you can enumerate all such files using the vscode.workspace.workspaceFolders and fs.readDir APIs.
vscode.workspace.workspaceFolders!.forEach(workspaceFolder => {
const snippetFiles = fs.readdirSync(path.join(workspaceFolder.uri.fsPath, '.vscode'))
.filter(el => /\.code-snippets$/.test(el));
});
Similarly, the global snippets get added as .code-snippets files into the user profile folder - on Windows it looks like this: C:\Users\currentUser\AppData\Roaming\Code\User\snippets\*.code-snippets. Both locations you can scan for *.code-snippets files as well as programmatically add such files to those folders.
Here is the documentation how to add snippets to a scope via a file. There does not seem to be any public API to enumerate all such snippet files in a programmatic way.
But if you want to retrieve list of the languages in the screenshot you posted, use this API:
vscode.languages.getLanguages()
It could help if you explained what are you trying to achieve. Do you want to find where a particular snippet is coming from to change it? Do you want to add a snippet to a language in this list? Or to a language that is not on this list?
Related
I'm in a bit of a pickle. I created custom files templates for my Xcode projects.
In a normal project environment my custom templates appear when I access the New file creation popover as you can see in the following screenshoot
These templates are located at the common path of: /Users/XXXX/Library/Developer/Xcode/Templates
The problem appear when I'm working on a swift package.
When I try to create a new file the popover interface is very different and does not contain my custom templates as seen with in the following image:
My suspicion is that I should set my templates in an other specific location for swift packages but I don't know where. I have looked around and I don't seems to find any reference to where I should set custom content for Swift Packages.
I'm looking for any tips on that matter. Or any information that could give me a some clues on how to fix my issue.
Thank you in advance.
I was asking myself recently if it is possible to add snippets to either one of the workspace, language-specific or global json snippet files through a VSCode extension.
// something like
Command.addSnippet('''
{
"prefix": "my_snippt",
.... etc.
}
''')
Reading through the API documentation I did not find anything. If there is no way, how would you go about creating kind of a snippet manager?
You can use SnippetString and a CompletionItemProvider to dynamically suggest snippets.
Here is an example.
I am reading the android platform-build docs with gnu makefile(Android.mk) from https://android.googlesource.com/platform/build/+/master/core/build-system.html.
Now I met an issue I didn't find a related template example?
<h3><a name="templates"/>How to add another component to the build - Android.mk templates</h3>
<p>You have a new library, a new app, or a new executable. For each of the
common types of modules, there is a corresponding file in the templates
directory. It will usually be enough to copy one of these, and fill in your
own values. Some of the more esoteric values are not included in the
templates, but are instead just documented here, as is the documentation
on using custom tools to generate files.</p>
<p>Mostly, you can just look for the TODO comments in the templates and do
what it says. Please remember to delete the TODO comments when you're done
to keep the files clean. The templates have minimal documentation in them,
because they're going to be copied, and when that gets stale, the copies just
won't get updated. So read on...</p>
<h4>Apps</h4>
<p>Use the <code>templates/apps</code> file.</p>
<p>This template is pretty self-explanitory. See the variables below for more
details.</p>
As sections mentioned above I assume there are somethings named 'templates' directory for
a library, apps ... But I couldn't find that in android source tree.
Could anyone enlighten me?
The examples are not located in a templates subfolder, but in the same directory as build-system.html:
binary.mk, shared_library.mk, java_library.mk, and many more.
Note: Android is switching from the Makefile-based build system to Soong. You might want to consider switching, too.
I have been combing through VS Code API docs, and am trying to understand whether or not it is actually feasible to write an extension that can edit the global User Settings JSON file.
Am I correct in thinking that I can create my extension, add the metadata I'm after under the "contributes" section in the "configuration" child object, then based on those values when the plugin is activated, take action against the User's preferences JSON?
I've also looked at the Guides plugin's configuration to check other examples, I'm just having a hard time conceptualizing how all this works, so any pointers would be appreciated.
I'm definitely NOT asking for someone to write my extension, just provide an answer as to whether I'm understanding the mechanics of an extension as a developer.
Would this work?
import { ConfigurationTarget, workspace } from 'vscode';
const configuration = workspace.getConfiguration(<YOUR_SECTION>);
configuration.update(<SETTING_NAME>, <SETTING_VALUE>, ConfigurationTarget.Global).then(() => {
// take action here
});
More information about the WorkspaceConfiguration object located here.
I'm trying to build a package for atom editor, I need to search for all local files in the project.
From https://atom.io/docs/api/v1.0.2/DirectorySearch I see DirectorySearch is an interesting class to search for specific text in local files.
There is little documentation on the page. I tried {DirectorySearch} = require 'atom' and new atom.DirectorySearch(). But they are not working, said "DirectorySearch is undefined".
I searched in atom's repository, but it seems that they only defined it. There is no usage of DirectorySearch. I also searched on Google and Stack Overflow but with no luck.
I'm using Version 1.0.2 on Mac OSX 10.
Can someone tell me how to import and use this class?
According to https://discuss.atom.io/t/how-to-import-and-use-directorysearch-in-atom/19205
Looking at the source it doesn't seem you can require it, but there's an instance of DefaultDirectorySearcher created in the workspace and available at atom.workspace.defaultDirectorySearcher that is used in the scan method as a fallback when a searcher for a directory haven't been specified.
If you want to search text in files, atom.workspace.scan should be enough.
You can also register a custom directory searcher using the atom.directory-searcher service, as far as I can tell, the object needs to implement the following methods to comply to the searcher interface:
-canSearchDirectory (directory:Directory) -> Boolean
-search(directories:Array, regex:RegExp, searchOptions:Object) -> CancellablePromise
The DirectorySearch class that appears in the docs is actually the CancellablePromise returned by the directory searcher.