GUI feature request "Add as import"

Thursday, 13 November 2014 · 5 messages · last reply 3 Jan 2016
AB
Andy Bunce13 Nov 2014 12:57 #
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
CG
Christian Grün16 Nov 2014 14:14 #
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
Quoted text · Andy Bunce · 19 lines
> 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 > > >
CG
Christian Grünin reply to Andy Bunce, 13 Nov 2014, 12:5723 Dec 2014 17:22 #
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
Quoted text · Andy Bunce · 22 lines
On Thu, Nov 13, 2014 at 12:57 PM, Andy Bunce <bunce.andy at 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 > > >
AB
Andy Bunce3 Jan 2016 00:15 #
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 :-).
Quoted text · Christian Grün · 1 line
>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
Quoted text · Christian Grün · 47 lines
On 23 December 2014 at 16:22, Christian Grün <christian.gruen at 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 at 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 > > > > > > >
CG
Christian Grün3 Jan 2016 12:50 #
Hi Andy,
Quoted text · Andy Bunce · 3 lines
> 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...).
Quoted text · Andy Bunce · 2 lines
> 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
Quoted text · Andy Bunce · 52 lines
> > /Andy > > On 23 December 2014 at 16:22, Christian Grün <christian.gruen at 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 at 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 >> > >> > >> > > >

⚡Generated with XQuery