Ticket #3434 (closed feature request: fixed)

Opened 4 years ago

Last modified 4 years ago

improve vi tags (add non-exported symbols, add tag kinds, add regex tags)

Reported by: phercek Owned by: simonmar
Priority: high Milestone: 6.12.1
Component: GHCi Version: 6.10.4
Keywords: vim tags ctags Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: Difficulty: Unknown
Test Case: Blocked By:
Blocking: Related Tickets:

Description

Ghci :ctags command does not generate tags for non-exported top level symbols. It also does not add type hints (vim kinds) to tags and does not allow generation of tags which are searched based on a regular expression instead of a line number. All these features of tags are supported well by vim but they are not supported by :ctags command.

New :ctags syntax should be: :ctags[!] [file]

The new command should generate tags for all top level symbols (regarles whether they are exported). The non-exported symbols should be marked as static in vim tags file. Vim tag kind field should be filled in with a haskell type hint. If the exclamation mark is added then the Ex address expressions in vim tags file should be based on search expression instead of line number. The search exression should search the whole line. This would provide better resistance to edits of unrelated lines.

The problem was discussed here:  http://www.haskell.org/pipermail/glasgow-haskell-users/2009-June/017399.html

The ticket is supported by me and Claus Reinke. Rest of the comunity did not indicate their (positive or negative) opinion.

Attachments

improveVimTags.dpatch.8.bz2 Download (92.5 KB) - added by igloo 4 years ago.

Change History

Changed 4 years ago by phercek

I wanted to attach a solution to this ticket but the darcs patch file is too big to be accepted. The patch itself has only about 300 lines and modifies only two files but the darcs context is big. You can download the patch here:  http://www.hck.sk/users/peter/pub/ghc/improveVimTags.dpatch

Changed 4 years ago by igloo

Changed 4 years ago by igloo

  • difficulty set to Unknown
  • milestone set to 6.14.1

Changed 4 years ago by igloo

  • owner set to simonmar
  • priority changed from normal to high
  • milestone changed from 6.14.1 to 6.12.1

Assigning to Simon, as he said "If the patch goes in, I can do a quick test of :etags under emacs.".

Changed 4 years ago by phercek

You can ignore this comment completely. It is just about some ideas for emacs support which I do not really care about.
I do not know emacs at all (installed it just now and read a bit about emacs TAGS in the manual). Anyway I tried two things: adding tag kinds and adding static tags to emacs TAGS.
Although emacs does not have a special field for a tag kind it solves it by adding /<kindLetter> to the tag name to distinguish different kinds with the same name. This is the way how it is done for Ada code so here is a patch which does the same for Haskell (it must be applied on top of improveVimTags.dpatch):

diff -rN -u old-ghc.head/ghc/GhciTags.hs new-ghc.head/ghc/GhciTags.hs
--- old-ghc.head/ghc/GhciTags.hs	2009-09-12 11:06:48.735680788 +0200
+++ new-ghc.head/ghc/GhciTags.hs	2009-09-12 11:06:48.975681765 +0200
@@ -192,10 +192,10 @@
 
 -- etags format, for Emacs/XEmacs
 showETag :: TagInfo -> String
-showETag TagInfo{ tagName = tag, tagLine = lineNo, tagCol = colNo,
+showETag TagInfo{ tagName = tag, tagKind = kind, tagLine = lineNo, tagCol = colNo,
                   tagSrcInfo = Just (srcLine,charPos) }
     =  take colNo srcLine ++ tag
-    ++ "\x7f" ++ tag
+    ++ "\x7f" ++ tag ++ ('/':kind:[])
     ++ "\x01" ++ show lineNo
     ++ "," ++ show charPos
 showETag _ = ghcError (CmdLineError "missing source file info in showETag")

Addition of tag kinds for emacs seems to work well. But, as far as I could figure it out, emacs support for static tags (symbols with file scope) is worse compared to vim. It still kind of works. Emacs can cycle over all tags with given name but it does not prefer jump to a local tag (the tag in the same file from which the jump was initiated). So in the case of name clashes it often jumps to incorrect locations. I think it should be possible to write an emacs macro which does this well. Still, the result is that it is questionable whether emacs tags should contain non-exported top level Haskell definitions by default. If you think it should then a patch which adds them is here (it must be applied on top of improveVimTags.dpatch):

diff -rN -u old-ghc.head/ghc/GhciTags.hs new-ghc.head/ghc/GhciTags.hs
--- old-ghc.head/ghc/GhciTags.hs	2009-09-12 11:06:48.735680788 +0200
+++ new-ghc.head/ghc/GhciTags.hs	2009-09-12 11:06:48.975681765 +0200
@@ -139,7 +139,7 @@
   IO.try (writeFile file tags)
 
 collateAndWriteTags ETags file tagInfos = do -- etags style, Emacs/XEmacs
-  tagInfoGroups <- makeTagGroupsWithSrcInfo $filter tagExported tagInfos
+  tagInfoGroups <- makeTagGroupsWithSrcInfo tagInfos
   let tagGroups = map processGroup tagInfoGroups
   IO.try (writeFile file $ concat tagGroups)
 

Changed 4 years ago by simonmar

  • status changed from new to closed
  • resolution set to fixed

I have dutifully done a quick test of :etags under emacs, and tested the resulting TAGS file, and it seems to work.

Note: See TracTickets for help on using tickets.