Arg cannot be resolved when using defresource

284 Views Asked by At

I'm trying to use liberator macro defresource but the intellij IDE keeps returning the error "(arg) cannot be resolved"

I'm doing a project using clojure, ring and liberator, in this project i have the dependecies as

:dependencies [[org.clojure/clojure "1.10.0"]
                 [liberator "0.15.3"]
                 [compojure "1.6.0"]
                 [ring/ring-core "1.7.1"]]

in the code

(:require [liberator.core :refer [defresource resource]]
           [ring.middleware.params :refer [wrap-params]]
           [compojure.core :refer [defroutes ANY]]))
(defresource ok
             :available-media-types ["text/html"]
             :handle-ok "This is iia")
(defroutes app
           (ANY "/test" [] ok))
(def handler
  (-> app
      wrap-params))

when using defresource ok the message "ok cannot be resolved" keeps showing

2

There are 2 best solutions below

2
dpassen On

If you're using Cursive, you should be able to tell IntelliJ to treat defresource as a def.

See Cursive's macro docs.

0
Andrei Galatyn On

I guess you are using IntelliJ+Cursive:

  1. Put cursor at defresource.
  2. Alt+Enter on keyboard (or Show Context Actions from popup menu).
  3. You should see popup menu with two items, click Resolve liberator.core/defresource as....
  4. You should see some suggestions, click defn.

After that IntelliJ should treat all defresource in the code as defn and related warnings should disappear.