Why isn't info popping up when the mouse hovers over a function in a package - visual-studio-code

When the mouse pointer hovers over the name of a function created in my code a box pops up in the editor with information about that function. However, if the function is in a package nothing happens. For example, if the mouse pointer hovers over the word "DataFrame" in the second line of the code below no box with info pops up. This is not specific to package DataFrames.
using DataFrames
DataFrame(:A => [0])
In VSCode Settings the following is set:
Editor > Hover:Delay
200
Editor > Hover:Enabled
Checked
The IDE is Visual Studio Code version 1.71.2 and the OS is Windows 11. The programming language is Julia, version 1.8.1.
It used to work, something changed, I do not know what.
Any hints on why this is happening?

I believe I found the solution. I created a function that adds a package to the environment. It has the package name as its single argument.
function load_package(package_name::String; used = true, report = true)
str_ui = used ? "Using " : "Importing "
report && println(str_ui * "package $package_name")
if used
eval(Meta.parse("using $package_name"))
end
eval(Meta.parse("import $package_name"))
end
It works fine. The package is loaded. For example,
load_package("DataFrames")
does (almost) the same thing as
using DataFrames
The only difference is that Visual Code does not seem to notice that the package was loaded when the package is loaded with the loaded_package function but it does notice it when the package is loaded with the using command.
So to fix the problem I had to load my packages with using and import comands. After doing that the tooltips became visible upon hovering over the function names.
The reason I was using the function load_packages was to load sets of packages whose names were in string vectors.

Related

VSCode - auto_prepend_file for code suggestions

I have been using VS code instead of eclipse for the last few weeks and find it much quicker, easier to use. However there is one thing I can’t seem to figure out.
My php app calls a prepend file which initiates a class called GlobalClass:
$gc = new GlobalClass();
When I type $gc-> in eclipse I get all the functions prompted. This doesn’t work within VS Code.
If I add use GlobalClass or add the $gc = new GlobalClass(); to the top of the file then it works. Is there any way to declare this within VS Code or to point the editor to the code within the prepend file?

go to file in eclipse by using location datatype

When clicking on a location type in the output window of eclipse, you can go to that file (location).
I would like to be able to trigger this with a method in rascal.
So to be clear, I have the location of a java method, I would like to trigger eclipse to focus on this file through rascal.
Take a look at the util::Editors module. It contains an edit function that opens any file you pass it, with the relevant editor, with optional highlights.
Note, that if you have a logical location like java+method://... you will have to lookup the actual physical location of the method in the m3 model using IO:resolveLocation, and use that. For example:
rascal>import IO;
ok
rascal>resolveLocation(|java+method:///io/usethesource/impulse/language/LanguageRegistry/IMPFileEditorMapping/setTheDefaultEditor(org.eclipse.ui.IEditorDescriptor)|)
loc: |project://impulse/src/io/usethesource/impulse/language/LanguageRegistry.java|(15638,134,<433,8>,<436,9>)
rascal>openEditor(resolveLocation(|java+method:///io/usethesource/impulse/language/LanguageRegistry/IMPFileEditorMapping/setTheDefaultEditor(org.eclipse.ui.IEditorDescriptor)|))
You are looking for openEditor in util::ValueUI.
First import util::ValueUI;, then try
openEditor(|project://rascal/src/org/rascalmpl/library/Map.rsc|);
and an editor for the Map module will open.

Is there auto-import functionality for typescript in Visual Studio Code?

Is there any shortcut that will allow me to auto generate my typescript imports? Like hitting ctrl+space next to the type name and having the import declaration placed at the top of the file. If not, what about intellisense for filling out the module reference path so that I wont have to do it manually? I would really love to use vscode but having to do manual imports for typescript is killing me.
There are rumors of making it support tsconfig.json (well, better than rumors). This will allow us to be able to use all files for our references.
Your feature would be to create an auto import of all commonly used 3rd party libs into the typings. Perhaps auto scan the files and create a list of ones to go gather. Wouldn't it be fine to just have a quick way to add several of these using tsd directly from Code (interactively)?
I believe the plugin called "TypeScript Importer" does exactly what You mean: https://marketplace.visualstudio.com/items?itemName=pmneo.tsimporter .
Automatically searches for TypeScript definitions in workspace files and provides all known symbols as completion item to allow code completion.
With it You can truly use Ctrl+Space to choose what exactly You would like to be imported.
You can find and install it from Ctrl+Shift+X menu or just by pasting ext install tsimporter in Quick Open menu opened with Ctrl+P.
I know a solution for Visual Studio (not Visual Studio Code, I'm using the 2015 Community edition, which is free), but it needs some setup and coding -- however, I find the results to be adequate.
Basically, in Visual Studio, when using the Web-Essentials extension, .ts files can be dragged into the active document to automatically generate a relative reference path comment:
/// <reference path="lib/foo.ts" />
With which of course we might as well wipe it, because it's an import statement we need, not a reference comment.
For this reason, I recently wrote the following command snippet for Visual Commander, but it should be easily adaptable to other use casese as well. With Visual Commander, your drag the needed imports into the open document, then run the following macro:
using EnvDTE;
using EnvDTE80;
using System.Text.RegularExpressions;
public class C : VisualCommanderExt.ICommand
{
// Called by Visual Commander extension.
public void Run(EnvDTE80.DTE2 DTE, Microsoft.VisualStudio.Shell.Package package)
{
TextDocument doc = (TextDocument)(DTE.ActiveDocument.Object("TextDocument"));
var p = doc.StartPoint.CreateEditPoint();
string s = p.GetText(doc.EndPoint);
p.ReplaceText(doc.EndPoint, this.ReplaceReferences(s), (int)vsEPReplaceTextOptions.vsEPReplaceTextKeepMarkers);
}
// Converts "reference" syntax to "ES6 import" syntax.
private string ReplaceReferences(string text)
{
string pattern = "\\/\\/\\/ *<reference *path *= *\"([^\"]*)(?:\\.ts)\" *\\/>";
var regex = new Regex(pattern);
var matches = Regex.Matches(text, pattern);
return Regex.Replace(text, pattern, "import {} from \"./$1\";");
}
}
When running this snippet, all reference comments in the active document will be replaced with import statements. The above example is converted to:
import {} from "./lib/foo";
This has just been released in version 1.18.
From the release notes:
Auto Import for JavaScript and TypeScript
Speed up your coding with auto imports for JavaScript and TypeScript. The suggestion list now includes all exported symbols in the current project. Just start typing:
If you choose one of the suggestion from another file or module, VS Code will automatically add an import for it. In this example, VS Code adds an import for Hercules to the top of the file:
Auto imports requires TypeScript 2.6+. You can disable auto imports by setting "typescript.autoImportSuggestions.enabled": false.
The files attributes in the tsconfig.json file allows you to set your reference imports in your whole project. It is supported with Visual Studio Code, but please note that if you're using a specific build chain (such as tsify/browserify) it might not work when compiling your project.

problems with prefs.get and set ImageJ Macro

I'm trying to write a macro to save preferences and read them after closing and reopening ImageJ.
The saving works, but the macro isn't reading the file. Moreover when I try to use one of these two lines an error occurs that the variable "Prefs" is unknown.
int myNumber = Prefs.get("my.persistent.number", 0);
Prefs.savePreferences();
What am I doing wrong? please help me :-)
The ImageJ macro language itself does not support storing custom preferences. (Only the set of built-in options (accessible via Edit > Options in the menu) can be saved, restored and adjusted.) You need to resort to calling the Java class via call("ij.Prefs.get", "my.persistent.number", "0");.
The following ImageJ macro works in an up-to-date Fiji/ImageJ installation:
myNumber = call("ij.Prefs.get", "my.persistent.number", "0");
print(myNumber);
call("ij.Prefs.set", "my.persistent.number", 3);
In the first run, it prints 0; every following run will print 3; after restarting Fiji, it will print 3 again. In case it does not work for you even after updating to the newest version, please report a bug via Help > Report a bug, which will also submit essential information about your installation to the developers to help them fix the issue.
Using one of the many scripting languages however, you can access the ij.Prefs java class directly, as you are trying to do it. Just do not forget to import the class before using it. This is an example Javascript:
importClass(Packages.ij.Prefs);
myNumber = Prefs.get("my.persistent.number", 0);
Prefs.set("my.persistent.number", myNumber);
Hope that helps.

Autocomplete in wxpython if load from xrc

I am trying to work with xrc resource in wxpython.
It is good but where is one big "no" - there is no autocomplete of wxFrame class loadet from xrc. And other loaded from xrc classes too.
Is this right or I'am doing somthing wgong?
here is the part of code for example:
import wx
from wx import xrc
class MyApp(wx.App):
def OnInit(self):
if os.path.exists("phc.xrc"):
self.res = xrc.XmlResource("phc.xrc")
self.frame = self.res.LoadFrame(None, 'MyFrame')
self.list_box = xrc.XRCCTRL(self.frame, "list_box_1")
self.notebook = xrc.XRCCTRL(self.frame, "Notebook")
self.StatusBar= xrc.XRCCTRL(self.frame, "MFrame_statusbar")
self.list_ctrl= xrc.XRCCTRL(self.frame, "list_ctr_1")
Well, how good the autocomplete function is depends entirely on the editor/IDE that you are using. You didn't specify what you are using to write python scripts, but from personal experience I would say that it is probably true, that there is no autocomplete.
I've used Eclipse/PyDev, Spyder, SPE and PyCharm in the past and they all did not show an ability to autocomplete widgets created with XRC. You could still try to get the Emacs autocomplete for Python to work and try it there, but I doubt it'll work.
I did not find this a particular hindrance, but everyone's different, I guess. Hopefully, that answers your question.
Yes autocomplete wouldn't work here since our code doesn't know what the xrc is going to return. Your code gets to know about the type of variable (in this case, frame) only during runtime.
And, unfortunately/fortunately, we cannot assign 'type' to a variable in Python for the autocompletion to work.
But in Eclipse + PyDev plugin
you can add this statement for autocomplete to work:
assert isinstance(self.frame, wx.Frame)
autocomplete works after this statement.