Giter Club home page Giter Club logo

Comments (9)

Olical avatar Olical commented on May 14, 2024 1

from conjure.

Olical avatar Olical commented on May 14, 2024 1

Update to 9a3f021 to give it a try.

from conjure.

Olical avatar Olical commented on May 14, 2024 1

Perf should be fixed in the latest master. Also made the Deoplete source try to skip completion in comments and strings, isn't perfect but it's an improvement. You can use conjure#should_autocomplete in your plugin too if you want that extra "ready" and syntax check.

from conjure.

Olical avatar Olical commented on May 14, 2024

For future me reference: This is because the "find matching pairs to select a form" code (

(defn read-form
"Read the current form under the cursor from the buffer by default. When
root? is set to true it'll read the outer most form under the cursor."
([] (read-form {}))
([{:keys [root?]}]
;; Put on your seatbelt, this function's a bit wild.
;; Could maybe be simplified a little but I doubt that much.
(let [;; Used for asking Neovim for the matching character
;; backwards and forwards.
forwards (str (when root? "r") "nzW")
backwards (str "b" forwards)
get-pair (fn [s e]
[(api/call-function :searchpairpos s "" e backwards)
(api/call-function :searchpairpos s "" e forwards)])
;; Fetch the buffer, window and all matching pairs for () [] and {}.
;; We'll then select the smallest region from those three
[buf win cur-char & positions]
(api/call-batch
(concat
[(api/get-current-buf)
(api/get-current-win)
(api/eval* (str "matchstr(getline('.'), '\\%'.col('.').'c.')"))]
(get-pair "(" ")")
(get-pair "\\[" "\\]")
(get-pair "{" "}")))
;; If the position is [0 0] we're _probably_ on the matching
;; character, so we should use the cursor position. Don't do this for
;; root though since you want to keep searching outwards.
cursor (update (api/call (api/win-get-cursor win)) 1 inc)
get-pos (fn [pos ch]
(if (or (and (= cur-char ch) (nil-pos? pos))
(and (not root?) (= cur-char ch)))
cursor pos))
;; Find all of the pairs using the fns and data above.
pairs (keep (fn [[[start sc] [end ec]]]
(let [start (get-pos start sc)
end (get-pos end ec)]
(when-not (or (nil-pos? start) (nil-pos? end))
[start end])))
(->> (interleave positions ["(" ")" "[" "]" "{" "}"])
(partition 2) (partition 2)))
;; Pull the lines from the pairs we found.
lines (api/call-batch
(map (fn [[start end]]
(api/buf-get-lines buf {:start (dec (first start))
:end (first end)}))
pairs))
;; Build the potential results containing the form text, origin in the
;; document and local cursor position within that form.
text (map-indexed
(fn [n lines]
(let [[start end] (nth pairs n)]
{:form (read-range {:lines lines
:start (dec (second start))
:end (second end)})
:origin start
:cursor [(inc (- (first cursor)
(first start)))
(- (second cursor)
(second start))]}))
lines)]
) is taking pairs that are in comments into account. The (comment ...) block is fine since it's part of the source. I think the reader version (#_) is fine too.

Just need to exclude parens that are inside line comments (;), either I check if there's one on the line of the matched pair or I use the syntax highlighting. Maybe I can ask vim if the given character is within a string or comment, in which case I'll ignore it and search again.

from conjure.

Olical avatar Olical commented on May 14, 2024

Found a nice fix!

diff --git a/src/conjure/nvim.clj b/src/conjure/nvim.clj
index dd7f465..d02ca9f 100644
--- a/src/conjure/nvim.clj
+++ b/src/conjure/nvim.clj
@@ -56,9 +56,14 @@
          ;; backwards and forwards.
          forwards (str (when root? "r") "nzW")
          backwards (str "b" forwards)
+
+         ;; Ignore matches inside comments or strings.
+         ;; https://github.com/Olical/conjure/issues/34
+         skip "join(map(synstack(line('.'), col('.')), 'synIDattr(v:val, \"name\")')) =~? 'comment\\|string' ? 1 : 0"
+
          get-pair (fn [s e]
-                    [(api/call-function :searchpairpos s "" e backwards)
-                     (api/call-function :searchpairpos s "" e forwards)])
+                    [(api/call-function :searchpairpos s "" e backwards skip)
+                     (api/call-function :searchpairpos s "" e forwards skip)])
 
          ;; Fetch the buffer, window and all matching pairs for () [] and {}.
          ;; We'll then select the smallest region from those three

Discovered the skip argument in :h pairpos(), I now provide an expression that rejects any matches found in strings or comments.

from conjure.

Olical avatar Olical commented on May 14, 2024

Fixed in v0.13.0... I think.

from conjure.

jlesquembre avatar jlesquembre commented on May 14, 2024

Thanks for fixing it. I just tried it and looks good :)

from conjure.

Olical avatar Olical commented on May 14, 2024

from conjure.

jlesquembre avatar jlesquembre commented on May 14, 2024

Thanks for the info, just updated CoC plugin

from conjure.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.