dkogan / xcscope.el

cscope interface for (X)Emacs
120 stars 29 forks source link

xcscope don't work with sub-directories #29

Open bsdmp opened 2 years ago

bsdmp commented 2 years ago

I've read the docs, but still can't make xcscope.el work with sources in sub-directories.

files in the directory:

cscope.out
[...]
got/
lib/

I start emacs got/got.c, then point cursor to the function, which is defined in file inside lib/ directory, and press C-s c d, and I get:

Finding global definition: got_worktree_open
Database directory: /home/misha/work/got/

cscope: no source files found

Search complete.  Search time = 0.02 seconds.

If I patch xcscope.el with the following:

--- xcscope.el.orig     Sun Mar 13 22:34:38 2022
+++ xcscope.el  Sun Mar 13 22:34:47 2022
@@ -2500,7 +2500,7 @@
     (save-excursion
       (catch 'finished
        (set-buffer outbuf)
-       (setq options '("-L"))
+       (setq options '("-LR"))
        (while (and (not done) cscope-search-list)
          (setq next-item (car cscope-search-list)
                cscope-search-list (cdr cscope-search-list)

everything starts working, and I get window with function name, and can jump to file inside lib/ directory.

I can't imagine that I'm first person, who has source files in different sub-directories. Am I missing something obvious?

OS: OpenBSD current Cscope: cscope-15.9p0

dkogan commented 2 years ago

Hi. Thanks for the report. Maybe the docs don't make this clear, but the expectation is that you build an index in the root of your project (with C-c s I), and then you can run searches. The command to build the index DOES recurse.

If you try to search, and an index isn't found, cscope will try to build a new index. THIS is the case you're hitting, where adding -R makes things work better. I'll be honest, I don't remember how building the index explicitly with C-c s I is better than doing it implicitly, with just running a search. Looking at the code doesn't make the answer immediately obvious. So without a deeper look, I'd rather not add -R to the default options. Are you OK with building an index explicitly?

bsdmp commented 2 years ago

Thank you for the fast reply. I've tried C-c s I and got the following:

Creating cscope index `cscope.out' in:
        /home/misha/work/got/

===============================================================================
Creating list of files to index ...
find: -false: unknown option
Creating list of files to index ... done
Indexing files ...
cscope: no source files found
Indexing files ... done
===============================================================================

Indexing finished

It looks like -false is not defined in POSIX and is GNU extension.

I tried following command: find . -name *.c -o -name *.h > cscope.files and then cscope -b in /home/misha/work/got directory - after that everything started to work.

So, it looks like that the error was in not having cscope.files file and not build cscope.out out from it.

If you want to make creating cscope.files more POSIX friendly - I'm ready to test the patch, if not, I think, the bug can be closed. (Probably worth mentioning this behavior in docs, though)

dkogan commented 2 years ago

Hi. Thanks. I haven't tried this on a non-GNU system, and I guess it doesn't work.

If you have a patch to eliminate the -false that you don't have on OpenBSD, that'd be good. It looks like I'm using it to terminate a sequence of OR operations. I have

EXPRESSION -o EXPRESSION -o EXPRESSION -o false

And the patch should turn this into

EXPRESSION -o EXPRESSION -o EXPRESSION

Was the missing -false the only part of the "find" expression that isn't supported for you?

bsdmp commented 2 years ago

I removed -o -false from the xcscope.el, cscope.files file is created, but it is empty, and building of cscope.out is failing because of it.

--- xcscope.el.orig     Sun Mar 13 23:11:36 2022
+++ xcscope.el  Mon Mar 14 14:43:55 2022
@@ -2734,16 +2734,14 @@

                     ;; apply -prune to any directory we're supposed to ignore
                     "(" "-type" "d" "("
-                    ,@(apply 'append (mapcar (lambda (dir) (list "-name" dir "-o") )
+                    ,@(apply 'append (mapcar (lambda (dir) (list "-name" dir) )
                                              cscope-indexer-ignored-directories))
-                    "-false"
                     ")" "-prune" ")" "-o"

                     ;; accept only files that match the patterns we want
                     "("
-                    ,@(apply 'append (mapcar (lambda (suffix) (list "-iname" suffix "-o"))
+                    ,@(apply 'append (mapcar (lambda (suffix) (list "-iname" suffix))
                                              cscope-indexer-suffixes))
-                    "-false"
                     ")"

                     ;; accept files and symlinks

Can you prompt me - how to debug what arguments are passed to find to execute them in a shell, and find the problem? I tried adding (message ...) to the code, but it is first time I use or see lisp, so my approach has failed.

bsdmp commented 2 years ago

I did a little bit more investigation, it looks like you're doing cycle to build find string like this:

-iname <suffix> -o
-iname <suffix> -o
[...]
-iname <suffix> -o

and after that appen -false, so you don't leave last -o without argument.

My lisp skills definitely don't allow me to fix this now. Maybe it's really should be just mentioned in docs, that cscope.files need to be presented in root dir of the project and that cscope -b must be run manually to xcscope to work on non-GNU OSes.

dkogan commented 2 years ago

Hi. Thanks for looking at it. I'll definitely make an update to the docs, but if -false is the only problem, I'd like to make this work on non-GNU boxes. I'll fix the lisp. Can you confirm that if you manually remove the "-o -false" then the find command works on your box?

bsdmp commented 2 years ago

I added printing of findargs with following code:

(message "findcmds: %s" findargs)

and it gives the following:

findcmds: (. \( -type d \( -name CVS -o -name RCS -o -name SCCS -o -name .git -o -name .hg -o -name .bzr -o -name .cdv -o -name .pc -o -name .svn -o -name _MTN -o -name _darcs -o -name _sgbak -o -name debian -o -false \) -prune \) -o \( -iname \*.\[chly] -o -iname \*.\[ch\]xx -o -iname \*.\[ch\]pp -o -iname \*.cc -o -iname \*.hh -o -false \) \( -type f -o -type l \) -print)

if I manually remove first ( and last ), and also remove two -o - false snippets and pass this to OpenBSD's find I successfully get expected results.