Hi,
I often find myself adding module imports in the GUI and I wonder if the following suggestion might speed up that process.
Add a new menu item to the filelist right click context menu "Add as import" when the file selection is a XQuery module.
The action would be to add a line to the current edit window source with
import module namespace {$prefix} = '{$namespace}' at {$path};
Where $prefix and $namespace} are read from the source of the selected file, and $path is calculated from the relative path from the edit file source to the selected filelist source. The line would be inserted at a suitable place in the prologue or at the current location if that is too tricky.
/Andy
Hi Andy,
thanks for the useful feature request. As I need some more thoughts on how to implement this properly, I have added a new GitHub issue [1]. Currently (and I guess you do something similar), I usually open the module to be imported, I copy the module declaration, paste it to the importing module and add the relative URL.
A good alternative would be to have an "Organize Import" feature similar to the one in Eclipse (triggered e.g. by the shortcut Ctrl+Shift+O), which automatically adds modules that have not been imported yet, and removes unused imports from the query prolog.
For all of those features, we could either decide to offer straightforward solutions that work in 90% of the cases, but that are not based on parsing the code, and thus fail miserably in the remaining cases. Of course, my preference would be to do it right, but it may then happen that nothing happens at all…
Christian
[1] https://github.com/BaseXdb/basex/issues/1027
I often find myself adding module imports in the GUI and I wonder if the following suggestion might speed up that process.
Add a new menu item to the filelist right click context menu "Add as import" when the file selection is a XQuery module.
The action would be to add a line to the current edit window source with
import module namespace {$prefix} = '{$namespace}' at {$path};
Where $prefix and $namespace} are read from the source of the selected file, and $path is calculated from the relative path from the edit file source to the selected filelist source. The line would be inserted at a suitable place in the prologue or at the current location if that is too tricky.
/Andy
Hi Andy,
I have added your requested menu item "Add as Import" in BaseX [1]. The feature, as implemented right now, feels a bit dodgy, because it does many things in one place (parsing a file, extracting things, building a string, adding it to the editor), and I haven't checked all possible error cases yet. But after all it cannot cause any real problems.. I decided to add the import statement at the cursor position. It's probably the most flexible solution as long as we don't do real parsing.
Cheers, Christian
[1] https://github.com/BaseXdb/basex/issues/1027
On Thu, Nov 13, 2014 at 12:57 PM, Andy Bunce bunce.andy@gmail.com wrote:
Hi,
I often find myself adding module imports in the GUI and I wonder if the following suggestion might speed up that process.
Add a new menu item to the filelist right click context menu "Add as import" when the file selection is a XQuery module.
The action would be to add a line to the current edit window source with
import module namespace {$prefix} = '{$namespace}' at {$path};
Where $prefix and $namespace} are read from the source of the selected file, and $path is calculated from the relative path from the edit file source to the selected filelist source. The line would be inserted at a suitable place in the prologue or at the current location if that is too tricky.
/Andy
Hi Christian,
I never got round for thanking you for this, I found it a great time saver , but it was a bit dodgy and now it seems it has gone in the latest 8.4 :-).
It's probably the most flexible solution as long as we don't do real
parsing.
And now you do? What I really want, in the editor, is an module import wizard that allows me to pick from a variety of sources e.g. relative files, the repository
/Andy
On 23 December 2014 at 16:22, Christian Grün christian.gruen@gmail.com wrote:
Hi Andy,
I have added your requested menu item "Add as Import" in BaseX [1]. The feature, as implemented right now, feels a bit dodgy, because it does many things in one place (parsing a file, extracting things, building a string, adding it to the editor), and I haven't checked all possible error cases yet. But after all it cannot cause any real problems.. I decided to add the import statement at the cursor position. It's probably the most flexible solution as long as we don't do real parsing.
Cheers, Christian
[1] https://github.com/BaseXdb/basex/issues/1027
On Thu, Nov 13, 2014 at 12:57 PM, Andy Bunce bunce.andy@gmail.com wrote:
Hi,
I often find myself adding module imports in the GUI and I wonder if the following suggestion might speed up that process.
Add a new menu item to the filelist right click context menu "Add as
import"
when the file selection is a XQuery module.
The action would be to add a line to the current edit window source with
import module namespace {$prefix} = '{$namespace}' at {$path};
Where $prefix and $namespace} are read from the source of the selected
file,
and $path is calculated from the relative path from the edit file source
to
the selected filelist source. The line would be inserted at a suitable
place
in the prologue or at the current location if that is too tricky.
/Andy
Hi Andy,
I never got round for thanking you for this, I found it a great time saver , but it was a bit dodgy and now it seems it has gone in the latest 8.4 :-).
I should have told you about the recent removal… When having another look at the feature, it didn’t feel good indeed, because it was simply too much of a hack. For now, you can possibly save some time by typing "im" and ctrl-space (but you’ll have to add the module prefix, namespace and location by yourself...).
What I really want, in the editor, is an module import wizard that allows me to pick from a variety of sources e.g. relative files, the repository
Oh yes, me too ;) In BaseX 8.4, as you may have seen, all erroneous files in the project view, and their ancestor directories, will be highlighted red. This is because XQuery modules are now compiled in the background, and it may be the first step to provide some context-aware code completion.
Cheers, Christian
/Andy
On 23 December 2014 at 16:22, Christian Grün christian.gruen@gmail.com wrote:
Hi Andy,
I have added your requested menu item "Add as Import" in BaseX [1]. The feature, as implemented right now, feels a bit dodgy, because it does many things in one place (parsing a file, extracting things, building a string, adding it to the editor), and I haven't checked all possible error cases yet. But after all it cannot cause any real problems.. I decided to add the import statement at the cursor position. It's probably the most flexible solution as long as we don't do real parsing.
Cheers, Christian
[1] https://github.com/BaseXdb/basex/issues/1027
On Thu, Nov 13, 2014 at 12:57 PM, Andy Bunce bunce.andy@gmail.com wrote:
Hi,
I often find myself adding module imports in the GUI and I wonder if the following suggestion might speed up that process.
Add a new menu item to the filelist right click context menu "Add as import" when the file selection is a XQuery module.
The action would be to add a line to the current edit window source with
import module namespace {$prefix} = '{$namespace}' at {$path};
Where $prefix and $namespace} are read from the source of the selected file, and $path is calculated from the relative path from the edit file source to the selected filelist source. The line would be inserted at a suitable place in the prologue or at the current location if that is too tricky.
/Andy
basex-talk@mailman.uni-konstanz.de