Can not import and use DirectorySearch in atom.io - coffeescript

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.

Related

Call a Dart const from a String version of its name

I am using Flutter and the FontAwesome library and I need to create icons based on their name. So, I need to get the following:
FaIcon(FontAwesomeIcons.lightWalking);
...but from its name as a String.
Something like this:
FaIcon(FontAwesomeIcons["lightWalking"]); // <== this doesn't work in Dart
I can then build a function to return icons based on the name that I get out of a database.
I don't think this is a dart related question on first sight but rather a FontAwesomeIcons question unless you want to use reflection in dart. You need to access the Icons here which are simply not accessible the way you tried it.
See the following issue:
https://github.com/fluttercommunity/font_awesome_flutter/issues/102
Quote:
Hi, we don't support icon maps officially, but you can use this
generator by calling it in the updater tool. You will need a local
installation of font awesome for this, please follow the instructions
for pro icons and ignore steps that mention icons.json or .ttf files.
If you need further assistance feel free to ask.
That means the way you are trying to access your icons is not supported directly.
However you could use the generator tools to create such a map, iterate it and find a suitable icon. See the FontAwesome example for that (they generated a map and iterated it).
https://github.com/fluttercommunity/font_awesome_flutter/tree/master/example/lib
What might be a little more convenient might be a third party tool which already has such a map and allows you to search it.
https://pub.dev/packages/icons_helper/example
You can then do the following:
getIconUsingPrefix(name: "PREFIX.ICON_NAME")
You can achieve this only using reflection. There is a library called reflectable for Flutter. It will generate some code for you and then you will be able to access the class members of FontAwesomeIcons by their name as String.

Get Visual Studio Code snippets scope programmatically using API

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?

How to access per project / per preset configuration data in vue-cli 3.x?

I'm looking to create a vue-cli 3.x plugin that generates extra files in the project when invoked and templates these based on configuration info entered by the user.
It's rather easy to collect this information from user prompts but it'd be much nicer if users could put this info into some sort of configuration file and have the plugin read it from there.
I understand vue-cli now uses a vue.config.js file on the project level and ~/.vuerc on a more global (preset) level. However, it doesn't look like my generator function would have access to either one of those files.
"The entire preset" should be passed as the third argument to the function when invoking the plugin with module.exports = (api, options, rootOptions) => {} in ./generator/index.js, rootOptions is undefined.
Sililarly, the use of vue.config.js is discussed in the documentation when talking about service plugins, but there's no mention how to use it in a generator function.
Am I missing something obvious here or is there really no officially sanctioned way to do this? Nothing stops me from reading vue.config.js in my function, but this feels hacky. And I wouldn't even know how to find out which preset was used to create the project.
So your problem is that you can't find ~/.vuerc?
I had the same issue and I found the solution here.
The solution is to use the command line
vue config
to see .vuerc, and then use
vue config --delete presets.yourPresetName
to delete your preset.
As well, if you can't type in your preset name in the terminal because it contains a space or an apostrophe, you can use
vue config --edit
to open .vuerc with a text editor and just edit it there

Show error marker for external resource

I have written an eclipse editor that performs syntax checking and if it finds an error, it will display it in the editor.
Currently I am doing this by creating a marker in the respective IResource and that is working well until the user uses the File -> Open File... option in order to open a non-project file with that editor.
The problem is that the EditorInput is no longer an IFileEditorInput (it's a FileStoreEditorInput) that allowed me to retrieve the connected IResource via getFile() (on which I can add the marker via createMarker()). In fact the core problem is that the opned file isn't an IResource at all (at least that is what I'm guessing as it is not in the eclipse workspace).
Is there another way of showing the error markers in the editor? It doesn't need to be savable or anything... Just a way to tell the editor to create the same markers in the source code as if there were some IMarker attached to the opened IResource.
Okay the thing was that I was actually looking for the creation of an Annotation in the AnnotationModel of the DocumentProvider. There it could be added via addAnnotation.
That approachs works fine. However I haven't found a list of available annotation types (as there are for Markers), so it's a little tricky to actually get the proper annotation...

Get object instances for a class

I have an instance file register for a custom MultiDataObject in System FileSystem entry: Loaders/text/custom-mime-type/Factories.
My application creates this objects when I open a project and my LogicalView creates the nodes for files in that project.
I need to get a list of instances for those MultiDataObject type, but I've not found way to achieve this.
I try to get this using Lookups.forPath, but anything returned.
¿Any clue for this issue?
With some reflection magic you can get them from a DataObjectPool - package private class in Data Loaders module (see openide.loaders/src/org/openide/loaders/DataObjectPool.java in NetBeans sources). There is no official API of this kind. Intentionally.
I'd say there is something wrong if you need this information. Perhaps you would get better advice if you had explained better what you want to achieve. Asking at NetBeans forum / mailing list will increase your chances even higher.