edts icon indicating copy to clipboard operation
edts copied to clipboard

edts always shows functions defined in ':lib-dirs' with red-underline and as 'undefined'

Open iambumblehead opened this issue 11 years ago • 13 comments

edts always shows functions defined in ':lib-dirs' with red-underline and as 'undefined'.

I'm not sure how to debug this. My lib dirs looks like this:

:lib-dirs '("src" "deps")

In deps I have 'bcrypt'. deps/bcrypt/ebin/bcrypt.app does exist. But bcrypt:start(), has a red underline and hovering the mouse shows a message box 'Call to undefined function bcrypt:start/0'. The primary application modules found in 'src' are found and edts will autocomplete the method names as I type them.

Can you tell me what I might be doing wrong? This application does build and run correctly.

iambumblehead avatar Dec 23 '14 23:12 iambumblehead

https://github.com/tjarvstrand/edts/issues/148

I've found that I can open/save a file found in the deps directory and afterward edts recognizes the module and its functions.

iambumblehead avatar Dec 25 '14 07:12 iambumblehead

TJ,

I'm trying to solve the issue here: https://github.com/tjarvstrand/edts/issues/160

I have a project with several dependencies. I thought to prototype something which would read *.erl files from those dependencies and then call edts funs against those so that my own project could use functions from those without edts showing the red underline.

I'm looking at this file https://github.com/tjarvstrand/edts/blob/master/elisp/edts/edts-code.el

Can you tell me what the next step is here?

I've sent you this in an email as well. Did you get the email?

Chris


(defun edts-compile-file (module-file)
  (let ((extn (file-name-extension module-file)))
    (if (equal extn "erl")
        (print module-file)))) ;; <-- what to add here?

(defun edts-compile-dir (module-dir)
  (f-files (concat module-dir "/src") 'edts-compile-file))

(defun edts-compile-libs (libs-dir)
  (f-directories libs-dir 'edts-compile-dir))

(global-set-key
 (kbd "C-c e")
 (lambda() (interactive)
   (let* ((project-root "/home/duko/Software/ganimas")
          (project-deps (concat project-root "/deps")))
     (edts-compile-libs project-deps))))

iambumblehead avatar Dec 26 '14 04:12 iambumblehead

I'm calling edts-api-compile-and-load-async but there is an error:

EDTS [error]: Unexpected reply: (404 Object Not Found) [118 times]

When I call this, EDTS is running.

;; (edts-api-compile-and-load-async Module File Cb)
;; Module ex, 'file.erl'
;; File ex, '/full/path/to/file.erl'
(defun edts-compile-file (module-file)
  (let ((extn (file-name-extension module-file)))
    (if (equal extn "erl")
        (let ((module-name 
               (file-name-sans-extension
                (file-name-nondirectory module-file))))
          ;; EDTS [error]: Unexpected reply: (404 Object Not Found) [118 times]
          (edts-api-compile-and-load-async 
           module-name module-file '(lambda () (print " callback ")))))))

(defun edts-compile-dir (module-dir)
  (f-files (concat module-dir "/src") 'edts-compile-file))

(defun edts-compile-libs (libs-dir) 
  (f-directories libs-dir 'edts-compile-dir))

(defun edts-compile-projectlibs () 
  (interactive)
  (let* ((project-root "/home/duko/Software/ganimas")
         (project-deps (concat project-root "/deps")))
    (edts-compile-libs project-deps)))

(global-set-key 
 (kbd "C-c e") 'edts-compile-projectlibs)

I added this to the 'load-async function and turned on the debugger

(print (concat module " - " node-name " - " file))

Here is what I see:

"yaws -  - /home/duko/Software/ganimas/deps/yaws/src/yaws.erl"

EDTS [debug]: Compiling yaws async on nil
EDTS [debug]: Sending async POST-request to http://0:4587/nodes//modules/yaws?file=/home/duko/Software/ganimas/deps/yaws/src/yaws.erl

iambumblehead avatar Dec 26 '14 19:12 iambumblehead

I have a solution here that is working for me.

I defined and alternative to edts-api-compile-and-load-async called edts-compile-and-load. node-name there may be passed in as an optional 4th param.

This compiles the files in the deps directory and now edts recognizes them when they are used in my project sources.

(defun edts-compile-and-load (module file callback &optional node-name)
  "Compile MODULE in FILE on the node associated with current buffer,
asynchronously. When the request terminates, call CALLBACK with the
parsed response as the single argument."
  (let* ((node-name   (if node-name node-name (edts-api-node-name)))
         (resource    (list "nodes" node-name "modules" module))
         (rest-args   (list (cons "file" file)))
         (cb-args     (list callback 201)))
    (print (concat module " - " node-name " - " file))
    (edts-log-debug "Compiling %s async on %s" module node-name)
    (edts-rest-post-async resource
                          rest-args
                          #'edts-api-async-callback
                          cb-args)))

;; (edts-api-compile-and-load-async Module File Cb)
;; Module ex, 'file.erl'
;; File ex, '/full/path/to/file.erl'
(defun edts-compile-file (module-file)
  (let ((extn (file-name-extension module-file)))
    (when (equal extn "erl")
      (let* ((module-name 
              (file-name-sans-extension
               (file-name-nondirectory module-file))))
        (edts-compile-and-load 
           module-name module-file '(lambda (comp-res) 
                                      (print (concat "compiled"))) "ganimas")))))

(defun edts-compile-dir (module-dir)
  (f-files (concat module-dir "/src") 'edts-compile-file))

(defun edts-compile-libs (libs-dir) 
  (f-directories libs-dir 'edts-compile-dir))

(defun edts-compile-projectlibs () 
  (interactive)
  (let* ((project-root "/home/duko/Software/ganimas")
         (project-deps (concat project-root "/deps")))
    (edts-compile-libs project-deps)))

(global-set-key (kbd "C-c e") 'edts-compile-projectlibs)

iambumblehead avatar Dec 26 '14 20:12 iambumblehead

I think the underlying problem is that EDTS currently doesn't keep track of changes in your declared lib-dirs so if a project node is started before deps are fetched, they won't be found until the node has been re-initialized. I'm working on a fix for it. Could this be why you're having these issues?

tjarvstrand avatar Dec 30 '14 16:12 tjarvstrand

When I begin editing project source files EDTS red underlines dependency function calls -they are not loaded in EDTS. I must do extra work getting definitions to EDTS -either opening and saving dependency files or by calling the functions I've made above. After I do that, EDTS recognizes the functions and gives auto-completion and other goodness.

I would like EDTS to auto-load dependencies for opened files so all functions used in the file are recognized and auto-completed right away with no added steps.

iambumblehead avatar Dec 30 '14 19:12 iambumblehead

Well, the idea is that it should do that. If it doesn't to that in the proper way then there's either a bug in EDTS or there's some problem with your configuration. You may however need to build your project before opening it in EDTS.

EDTS uses compiled beam files to figure out information about the project. This is because I wanted to keep it flexible and because it's not feasible to include support for all build-systems. There are macro definitions, include-locations, parse-transforms etc. etc. that are very difficult to figure out without including an entire build system. Instead of trying to keep track of this EDTS relies on the project's build system to take care of setting up such things and then just makes an effort to maintain that build configuration. It can get problematic at times, but I think it's more manageable than the alternative.

tjarvstrand avatar Dec 30 '14 20:12 tjarvstrand

It must be the result of a bug. I do have compiled sources. Before any file is opened rebar get-deps and rebar compile have been used and so beam files are there.

iambumblehead avatar Dec 30 '14 20:12 iambumblehead

https://github.com/iambumblehead/eds

For now I solve this problem by using this eds-compile.el file to compile the dependencies for my application when I edit with emacs.

iambumblehead avatar Jan 01 '15 04:01 iambumblehead

If it's the result of a bug it would be great if you could give a minimal example configuration and project to reproduce it.

tjarvstrand avatar Jan 01 '15 13:01 tjarvstrand

https://github.com/iambumblehead/edtsredunderline


use these source files to demonstrate the edts red underline bug.

$ git clone https://github.com/iambumblehead/edtsredunderline.git
$ cd edtsredunderline
$ rebar get-deps
$ rebar compile

Then open edtsredunderline.erl with emacs. Add whitespace and save the file. See red underline below bcrypt and childmaps.

iambumblehead avatar Jan 02 '15 04:01 iambumblehead

Unless I misunderstood you we can close this now right?

tjarvstrand avatar Jan 17 '15 09:01 tjarvstrand

The edtsredunderline repository is there for you to reproduce the issue, which I'm still experiencing. I see you've released an updated version of edts -I will see if I'm still experiencing the issue with that.


I still experience this issue using the latest edts, 20150117.503

iambumblehead avatar Jan 19 '15 03:01 iambumblehead

please reopen if still an issue

sebastiw avatar Sep 26 '23 08:09 sebastiw