334 Commits

Author SHA1 Message Date
Colomban Wendling
05fce1a2ee Move some functions from tm_tag to tm_parser namespace
Those don't actually work on tags, so it makes more sense to have them
in the parser namespace.
2017-09-23 12:53:59 -07:00
Colomban Wendling
198a0cf2ba Update a comment to better reflect the internal data changes 2017-09-23 11:59:20 -07:00
Colomban Wendling
6522332ba9 Fix the symbols tree hierarchy when several tags have the same name
Fix the symbols tree hierarchy by considering the whole scope when
adding a tag, avoiding choosing the wrong parent when several tags have
the same name.  Until now, to avoid such misbehavior we only used to
choose the parent candidate that appeared last (line-wise) before the
child.  It works in most typical situations as generally tag names are
fairly unique, and children appear right after their parent.

However, there are cases that are trickier and cannot be handled that
way.  In the following valid C++ snippet, it is impossible to know
whether `function` should be listed under the namespace `A` or the
class `A` without looking at its full scope:

```C++
namespace A {
    namespace B {
        class A {
            void method() {}
        };
    };
    void function() {}
};
```

And it is a real-world problem for some parsers like the JSON parser
that generates numeric indices for array elements name, often leading
to several possibly close duplicates.

Additionally, to prevent trying to set a tag as its own parent, the
code guarded against accepting a parent if the child had the same name,
lading to incorrect hierarchy for `method` in cases like this:

```C++
namespace A {
    class A {
        void method() {}
    };
};
```

So to fix this, consider the whole hierarchy of a tag for choosing its
parent, when that information is available from the parser.

Fixes #1583.
2017-09-01 17:31:56 -07:00
Matthew Brush
6d663cbb0e Change all scintilla_send_message calls to use SSM macro 2017-08-03 23:48:30 -07:00
Colomban Wendling
19af3caa73 Fix the current scope shown in the statusbar
Since the Scintilla C++ lexer started to fold on `()` [1], the code
looking up the current scope is confused whenever the function
signature spans multiple lines.  Fix this by skipping fold levels that
correspond to parentheses.

Fixes #1279.

[1] https://sourceforge.net/p/scintilla/feature-requests/1138/
    imported in 24f91981c057a7e212c09da66fb974c3ccc85bd6
2016-12-22 13:52:12 +01:00
Jiří Techet
3cf0161527 Store "equal" tags into binary trees instead of lists in Symbol tree
At the moment tags with identical names are stored into a linked list in
tags_table and parents_table. This however leads to quadratic complexity
when looking up the nearest parent or tag in tree because the whole list
has to be traversed.

Use binary trees indexed by line number instead of lists so the lookup can
be performed in log(N) time and the overall complexity is N*log(N) instead
of N^2.

The GTree API is a little stupid because during the search it doesn't give
access to the value and it doesn't tell when a leaf node was reached. For
this reason the lookup has to be made in two steps - first, the best line
number is found (returned in user_data) and then a normal search for the
found line number is made to get the value stored in the tree.

This patch fixes the problem described in #577 when e.g. a big json export
file contains many identically named tags.
2016-07-22 23:21:09 +02:00
Colomban Wendling
65988f51f0 style: Reduce scope of several variables
No behavioral changes.
2016-06-25 16:15:08 +02:00
Colomban Wendling
021bbfb82b Merge pull request #958 from techee/goto_popup
Improve Goto Symbol popup contents
2016-06-10 23:47:57 +02:00
Jiří Techet
20e3681558 Try harder when definition/declaration was not found
Even when we know when should be searching for definition (or declaration),
we can keep searching for the opposite type too when we didn't find
anything with the "correct" def/decl type. So at least we find "something"
of that name.
2016-06-09 10:01:59 +02:00
Jiří Techet
ca8ef9643e Add parentheses in an if to make the condition more clear 2016-06-09 09:41:09 +02:00
Colomban Wendling
854a5d5af8 Don't special-case tags files distributed with Geany
Load those tags files just as any user tags files, removing
unnecessary code redundancy.
2016-04-29 01:39:11 +02:00
Colomban Wendling
6b262bb4ec Make html_entities.tags a real tags file
This removes a fair amount of specific code that is just as well
handled by the generic symbols completion code.
2016-04-29 01:35:21 +02:00
Jiří Techet
3640b3bc44 Move *.tags files to the tags directory
ignore.tags is still in ~/.config/geany
2016-03-13 17:35:14 +01:00
Jiří Techet
65f84df5ca Improve Goto Symbol popup contents
* always filter-out symbol from the current line from the list
* when clicked on a symbol on the current line always swap
  definition/declaration search even if there are more symbols from the
  current search direction

Fixes #950
2016-03-11 11:29:50 +01:00
Colomban Wendling
32be0c910f Merge pull request #923 from techee/typedef_goto
Don't show the goto popup for typedef synonyms
2016-03-09 16:09:48 +01:00
Jiří Techet
c84c41e44a Don't show the goto popup for typedef synonyms
For instance when performing goto tag for Foo and Foo is defined as

typedef struct Foo {} Foo;

go immediately to the struct location without showing the goto popup with
both the struct name and typedef. When there are more occurrences of the
name, filter the list and don't show the synonyms in the popup.

In addition, if the cursor is on the same line as the typedef, go to
the struct and vice versa.

Note the missing

g_strcmp0(second->var_type, first->name) == 0

in the check - in this particular case we won't get the type to which the
typedef refers inside var_type because at the time the typedef tag is
generated in c.c the struct tag doesn't exist yet. On the other hand
there's no second->var_type == NULL either because this behaviour seems
to be rather implementation-specific and might easily change in the
future. The existing checks are probably sufficient for the real-world
code.
2016-03-05 11:10:38 +01:00
Colomban Wendling
856ee6633f Replace filetype_id with GeanyFiletypeID
Used only in static functions so no API change.
2016-03-04 23:07:04 +01:00
Colomban Wendling
be29bad098 Merge pull request #906 from techee/scope_fallout
Scope completion fallout patches
2016-03-04 20:06:10 +01:00
Colomban Wendling
6ba26cf1fe Use "symbol" instead of "tag" in comments too 2016-03-01 22:31:47 +01:00
Colomban Wendling
8b61b9f941 Mark the goto popup label as translatable for localized colons
It could arguably not be translatable and only `filename:line` display,
but as we have already a space on the right of the colon it's not, and
allowing translation is not a problem and can give better localization.
2016-02-28 13:27:31 +01:00
Jiří Techet
292383c197 Some more uses of TMParserType instead of int 2016-02-26 01:11:53 +01:00
Jiří Techet
d1a5ceac42 Don't pass multiple copies of identical type name to scintilla for colorization
For instance for the boost library this makes the resulting string passed
to scintilla 6x shorter. Because scintilla goes through this list more
or less linearly for every single word in the document, this can bring
significant reductions of time spent when recolorizing.
2016-02-26 01:10:00 +01:00
Jiří Techet
cb307e5b92 Use the langs_compatible() function when passing typenames to scintilla
This requires making the function public and tm_tag.c seems to be a better
place for the function than tm_workspace so move there and add the prefix.
2016-02-26 01:09:59 +01:00
Jiří Techet
5030f7f3da Cleanup NONE/AUTO filetype definitions
At the moment the Geany code uses arbitrary combination of the following
synonyms

TM_PARSER_NONE / LANG_IGNORE / -2
TM_PARSER_AUTO / LANG_AUTO / -1

Especially using just the numbers makes things very confusing.

In the Geany code this patch replaces all occurrences of -2 and LANG_IGNORE
with TM_PARSER_NONE. It also removes LANG_IGNORE from the header which
isn't needed any more.

In addition, TM_PARSER_AUTO/LANG_AUTO shouldn't be used at all. We want
filetype detection based on Geany's definitions and not based on the
hard-coded ctags definitions. Remove it completely.

Finally, as it's clearer now what the constants mean, the patch fixes the
implementation of langs_compatible() (tag or file can never be of type
AUTO but we should rather check for NONE filetypes which we should
consider incompatible between each other).
2016-02-26 01:09:59 +01:00
Jiří Techet
b46e183cbc Move the popup 1px further so it isn't below mouse pointer
Otherwise the mouse pointer highlights a wrong value if the popup is
large enough to extend above the mouse pointer.
2016-02-26 00:05:22 +01:00
Colomban Wendling
c8dd52eb46 Position the popup at the very click position if any 2016-02-26 00:05:22 +01:00
Colomban Wendling
653990c011 Pass the actual event button to gtk_menu_popup()
In case it's actually useful.  Also properly free the GdkEvent returned
by gtk_get_current_event().
2016-02-26 00:05:22 +01:00
Jiří Techet
a168f69887 Make sure the mouse cursor is out of the popup
The x coordinate is now taken from the scintilla caret position. However,
when performing ctrl+click, we have to distinguish two cases:

1. the click happens in the second half of a letter - in this case the caret
is placed behind the letter and the popup appears behind it - no problem

2. the click happens in the first part of a letter - caret is placed before
the letter and the popup appears before the position where the click
happened - this means that the mouse cursor is above the popup which causes
that the mouse cursor highlights the item at the position of the cursor
instead of having the first item in the menu highlighted.

The patch calculates offset between caret and the mouse click event
position and uses this value to adjust the popup positioning so it's
outside the mouse cursor.
2016-02-26 00:05:22 +01:00
Colomban Wendling
848a123f00 Improve placement of the goto tag popup 2016-02-26 00:05:22 +01:00
Jiří Techet
1f9bfdf65f Set push_in parameter to false
This behaves a bit strangely when the list is long and when clicked at the
bottom of the screen (the top part of the popup is empty).
2016-02-26 00:05:22 +01:00
Jiří Techet
61582a42f9 Always select the first item for better keyboard manipulation
Even when the user Ctrl+clicks to perform goto tag definition, it should
be possible to select the item from the list using keyboard (and have
the first item automatically selected so ctrl+click plus enter afterwards
always gets you somewhere).
2016-02-26 00:05:22 +01:00
Colomban Wendling
943bfa52c5 Re-implement goto tag popup with a poped-up GtkMenu 2016-02-26 00:05:22 +01:00
Jiří Techet
4c0c76e6f4 If more tags are found during tag definition/declaration goto, let user select which one to use
If only a single tag is found, just perform the goto. If more tags are found,
show them in a popup. Try to help the user find the right file by
putting the "best" tag at the first position and emphasizing it.

Thanks to Colomban Wendling for various improvements of this patch.
2016-02-26 00:03:45 +01:00
Colomban Wendling
2f55540f75 Merge pull request #582 from techee/tags_are_symbols
Use the word "symbol" instead of "tag" in the UI and documentation
2016-02-17 22:54:55 +01:00
Jiří Techet
9b686871de Use the word "symbol" instead of "tag" in the UI and documentation
For users a tag is <this> so the naming can be confusing.

The only exception where we probably shouldn't use the word symbol is the
"tags file" (*.tags) containing global tags - this has already the "tags"
extension and is more related to ctags and using "symbols file" is a bit
strange in this case.

As a result, the only places where this patch leaves the word "tag" are:

* phrase "tags file(s)"
* phrase "tags parser(s)"
* documentation mentioning the "tags" directory
* documentation mentioning the *.tags extension

and of course where it means the HTML/XML markup <thing>. The rest of the
uses of the word "tag" is replaced with "symbol".

Documentation is updated accordingly.

Fixes #579.
2016-02-17 22:38:00 +01:00
Jiří Techet
13755122f2 Move symbols_get_context_separator() implementation to TM
This way we can use it inside TM.
2016-01-10 12:31:47 +01:00
Jiří Techet
99e222ea37 Eliminate calls of slow tm_tags_extract() on big arrays
Do the same with struct/class/union... member tags as we do with
typenames - extract them from the edited file and merge them with
the array containing all of them so while editing, there should
be no slowdowns because one file usually doesn't contain so many
tags. This eliminates about 2s freeze when typing "." on a linux
kernel project with 2300000 tags.

Extract typename and member tags also for global tags in case someone
creates a giant tags file - this needs to be done just once when
loading the tag files.

All the remaining tm_tags_extract() in Geany are called on
file tag array only so there shouldn't be any performance problems.
2015-07-14 09:44:33 +02:00
Enrico Tröger
4017442f86 Merge pull request #477 from eht16/ctags_powershell
Add PowerShell tag parser
2015-07-04 12:52:46 +02:00
Enrico Tröger
8a6fbd9786 Add PowerShell tag parser 2015-06-28 15:46:23 +02:00
Colomban Wendling
5ebed27d4b Fix incorrect variadic argument type fetch (oops) 2015-06-21 14:23:44 +02:00
Colomban Wendling
cdd07e15f5 Fix unreffing NULL icons when generating tags 2015-06-15 00:09:13 +02:00
Colomban Wendling
23eff5cadf Over-engineer symbol tree icon cache a little
This will get useful to fix problems when generating tags.
2015-06-15 00:09:12 +02:00
Colomban Wendling
6792bf0db7 Simplify some code a little 2015-06-12 18:54:34 +02:00
Colomban Wendling
9458d5cfe6 Release symbols icons when quitting 2015-06-12 18:48:29 +02:00
Jiří Techet
62e6de9f10 Cache symbol tree icons
When profiling Geany I/O activity, there are lots of I/O operations happening
when just typing in the editor caused by the updates of the symbol tree
and loading the icon files.

In addition, in the case of tag_other the leaves of the tree use
classviewer-var instead of the parent icon (e.g. with enums). In this case
the icon is loaded from the disk every time it's requested which takes
about 70% of the tree creation time when the tree consists only of such
nodes.

To fix these problems load the icons once and return the loaded icons when
requested instead of reloading them from the disk all the time.
2015-06-11 12:42:28 +02:00
Jiří Techet
e973841cec Show go interfaces, structs and struct members in symbol tree 2015-05-28 16:22:54 +02:00
Jiří Techet
44fec8f751 Prepend values to GtkTreeStore to eliminate quadratic complexity
The tree model nodes consist of GNode structs:

struct GNode {
  gpointer data;
  GNode	  *next;
  GNode	  *prev;
  GNode	  *parent;
  GNode	  *children;
};

where children are a linked list. To append a value, the list has to be
walked to the end and with nodes with many children (which is our case)
this becomes very expensive.

We sort the tree afterwards anyway so it doesn't matter where we insert the
value.
2015-05-03 19:36:26 +02:00
Jiří Techet
e3e46ed63b Use gtk_tree_store_insert_with_values() to speed-up tree creation
About 30% faster tree creation.
2015-05-03 19:36:26 +02:00
Jiří Techet
35bde6c5ad Reload a tag in the sidebar only when it differs from the existing tag
gtk_tree_store_set() becomes very slow when the tree gets bigger
because internally it calls gtk_tree_store_get_path() which counts
all the entries in a linked list of elements at the same tree level
to get the tree path.

Avoid the call of this function when not needed.
2015-05-03 19:36:26 +02:00
Jiří Techet
5d94d15976 Reload tooltip in the symbol tree also on tag update
Because function return types are not used to determine tag equality,
we need to also update the tooltip of an existing tag otherwise the return
type doesn't get updated when changed.
2015-05-03 19:36:26 +02:00