QScintilla autocomplete on custom lexer in python - autocomplete

All,
I'm using QScintilla to syntax-highlight and autocomplete my domain specific language (DSL).
I wrote a custom lexer by re-implementing (QsciLexerCustom) and I'm trying to use the auto-completion.
My problem is that the auto-completion doesn't work like I want.
I'd like my custom lexer to work like the QsciLexerPython. That is, if i add 'toto.titi.tata' to the api, when i type 'toto.' in my qscintilla editor, it suggests me 'titi.tata'. As of now, it is suggesting me toto.titi.tata. :(
I tried to add 'autoCompletionWordSeparators' to my lexer but it is not working.
How can i make my custom lexer auto-complete work like the QsciLexerPython?
Thanks a lot !
Lexer = customlexer(self.text)
api = QsciAPIs(Lexer)
api.add('toto.titi.tata')
api.prepare()
Lexer.setAPIs(api)
self.text.setLexer(Lexer)
class lexer(QsciLexerCustom):
def __init__(self, parent):
QsciLexerCustom.__init__(self, parent)
def autoCompletionWordSeparators(self):
return ['.']

The current QScintilla APIs provide no way to do this.
The main obstacle is that many of the virtual methods you need to reimplement in a QsciLexerCustom subclass aren't public. This is why the code in your example doesn't work - your autoCompletionWordSeparators method is ignored when the lexer is set, and the base-class method from QsciLexer is called instead (which returns an empty list).
You might also think you could use QsciScintilla.setAutoCompletionWordSeparators to work around this, but alas, this only works if no lexer has been set!
The only way to solve this issue is to either implement auto-completion yourself (which is doable, but a lot of work), or make a feature request on the Qscintilla mailing list to get the necessary virtual methods added to the public API for QsciLexerCustom.
The methods in question are listed here (the names are shown in bold black, rather than as a link).

Related

Documentation of OCaml code in Eclipse

I'm using Eclipse with the OcaIDE-Plugin to write my ocaml-project.
I have written several ocaml-functions that I want to document (comment, return values and params).
I've created my documentation in the .ml-files like described in this link: http://caml.inria.fr/pub/docs/manual-ocaml/ocamldoc.html
Here is an example of one function:
(** sorting tuples where first element is key *)
let my_comp x y = (*Some code*)
Unfortunately, my comments don't show up, when I press F2 at one of the functions, it only shows the name and the file it is contained.
When writing comments in an mli-file, it works as expected, but i also want to document "private" functions that are not accessible from the outside. Can I define functions in the mli, that are NOT accessible from the outside, just for the documentation?
How can I make Eclipse to show my documention?
Well, as you said, you would like to show the documentation but not export the function out of the module. That, sadly, won't work.
I guess OcaIDE can be considered as incomplete but it doesn't look like it's something people care about (I don't know a single person working on OcaIDE). If you like having autocompletion etc, maybe try to program with emacs and install merlin (look, I found the perfect post for you : here)
As for the suggestion of defining a function in the mli not accessible from the outside, it's completely opposed to why mli files are created, so don't expect that to be possible. ;-)
I hoped I've been able to help you.

Code complete Siteprism's elements in Rubymine

I am automating using Selenium, Capybara and siteprism.
Using rubymine, I want to get code completion such that I can type #page. and get a list of the methods (this works) and a list of the elements and sections defined in the page object using siteprism.
Is there any way to do this in Rubymine?
Sublime text editor does this, but yet it doesn't handle the class names and methods very well.
In site-prism the methods on a page-object class such as the getters, waiters, etc are added dynamically by the class methods element, elements, section, sections when the class is evaluated. This adds several methods about a particular element for each listing in the class.
That means there's no way for rubymine to simply read the files looking for def to determine what methods should exist on any instance of #page.
You might be able to code something up to get it working, but there's no straightforward solution.

what makes a variable be visible (intellij idea)

With intellij idea, how do I find out what makes a variable be visible?
An example of when it is hard:
Suppose you look at class A, and you see a variable something. If you jump to source you see that it's defined in trait X. But you don't extend trait X directly. What do you extend, then, that makes this variable visible? If you have a deeply nested hierarchy, tracking can be hard.
Any recommendations or solutions?
EDIT: Please vote for the feature if you're interested: http://youtrack.jetbrains.com/issue/IDEA-124369
I don't think that IntelliJ IDEA has any shortcut for "finding what makes a variable visible".
However you can determine it using the "Find Usages" option (Alt + F7). For example:
import java.nio._
object TempObj extends App {
def func = 2
val p = file.Paths.get("some-path")
func
}
So Find Usages on "file", tells you that its from the Package "file" (in heading of the new Tab it also shows the complete package name, ex: Find Usages of java.nio.file in Project Files).
Whereas Find Usages on func will tell you that its a Method (And the Tab heading now says: Find Usages of func() in Project and Libraries)
So now in way you can determine, what exactly makes the variable visible. This also works for imports since it shows the package from which it is imported and you can then look for import of that packages.
I know of two almost-solutions to this problem.
Go-to-declaration, as you mentioned, solves this problem in the case of local variables.
More generally, the "find usages" feature gives you a neat little breakdown by type and file of different uses of the variable. From this you can see if it's involved in a static import.
It's not perfect, but with a moment's thought these two are generally sufficient to figure out what you want.
Use ctrl+b or F4 to jump to source code. Alternatively you can use ctrl+shift+a to get option/action. You can find shortcuts at http://gaerfield.github.io/ide-shortcuts/ as well. Hope it will help.
From what I understood you want to see the code that creates an Object you use, for instance Mystery someMystery;.
That gives you two options to populate someMystery:
someMystery = ... where ... is your code to populate
someMystery and if that is the case you should follow
that code (with ctrl+B as far as you need to) to the point where it
actually creates the Mystery object.
Use CDI to populate that object instance for you, in which case you should look into the CDI mechanism in order to see in what way the object instance is populated.
In either way IMO there is no way to know for sure if the someMystery instance is of some more concrete class than Mystery, because it is decided in runtime, not in compile time, so your next bet would be to run the program in debug and see what object goes into someMystery, although you are not guaranteed to get the same type of object every time.
PS. My answer is based entirely on my java understanding of the topic, can't say if it is valid for scala also.
This might not be exactly the answer you were hoping to get.
However, quoting yourself,
If you have a deeply nested hierarchy, tracking can be hard.
Have you considered using composition over inheritance? Perhaps this would remove the need for the feature you are looking for.
Deeply nested hierarchy doesn't sound good. I understand your pain about that.
When you override vals or defs there is a little circle next to the line number that shows where it is from even when it is from nested hierarchy. Hovering over vals with the command key down also shows you a little tooltip where it is from.
Does this help?
https://youtu.be/r3D9axSlBo8
if you want class, field or method to be visible, you need to implement them as public. If it was your question.

Can I use Eclipse templates to insert methods and also call them?

I'm doing some competitions on a website called topcoder.com where the objective is to solve algorithmic problems. I'm using Eclipse for this purpose, and I code in Java, it would be help me to have some predefined templates or macros that I can use for common coding tasks. For example I would like to write methods to be able to find the max value in and int[] array, or the longest sequence in an int[] array, and so on (there should be quite many of these). Note I can't write these methods as libraries because as part of the competition I need to submit everything in one file.
Therefore ideally, I would like to have some shortcut available to generate code both as a method and as a calling statement at once. Any ideas if this is possible?
Sure you can - I think that's a nifty way to auto-insert boilerplate or helper code. To the point of commenters, you probably want to group the code as a helper class, but the general idea sounds good to me:
You can see it listed in your available templates:
Then as you code your solution, you can Control+Space, type the first few characters of the name you gave your template, and you can preview it:
And then you can insert it. Be sure if you use a class structure to position it as an inner class:
Lastly - if you want to have a template inserts a call to method from a template, I think you would just use two templates. One like shown above (to print the helper code) and another that might look like this, which calls a util method and drops the cursor after it (or between the parentheses if you'd like, etc):
MyUtils.myUtilMethod1();${cursor}

Adding 'reference tables' to Doxygen

In my C++ application I have about 10 different classes that define certain 'behaviors' (let's call them A, B, C, ...). Other places (methods) in the code might use these behaviors in any combination. E.g. method M1 uses behaviors A and B, method M2 uses behaviors A, C and D, ...
In practice the code is similar like this:
BehaviorCollection coll;
BehaviorA ba;
coll.push_back(&ba);
BehaviorB bb;
coll.push_back(&bb);
someComplexFunctionality (coll);
I want to generate a clear overview of which method uses a behavior, preferably in the documentation of the specific behavior, so that the class documentation of every behavior contains a list like:
BehaviorA is used by the following methods:
- method1
- method3
- method7
I could hard-code this list but after a while it will become outdated because new methods are added, methods starts to use additional behaviors, or methods stop using behaviors.
So, to make this maintainable, I prefer to have something in the method using the behaviors, telling Doxygen "this code is using these behaviors, so add something in the documentation of that behavior".
Tools like "Visual AssistX" or "Understand for C/C++" allow me to perform the lookup but they still require some manual actions every time you want to do the lookup. Therefore I want to automate this in my documentation generation system.
I am considering using defgroup and ingroup, but I'm not sure this will work for code fragments.
What is the best approach to use?
I found a solution by using the xrefitem tag.
In every method using a behavior I added a line like this:
//! \xrefitem group_behaviorA_users "Behavior A users" "Behavior A Users"
And then the behavior itself contains a documentation line like this:
See \ref group_behaviorA_users for an overview of all users of this behavior.
Problem solved.