|
1 | 1 | (local {: autoload : define} (require :conjure.nfnl.module)) |
2 | 2 | (local a (autoload :conjure.nfnl.core)) |
3 | | -(local log (autoload :conjure.log)) |
4 | 3 | (local ts (autoload :conjure.tree-sitter)) |
5 | 4 | (local util (autoload :conjure.util)) |
6 | 5 | (local res (autoload :conjure.resources)) |
|
70 | 69 |
|
71 | 70 | (fn is-in-scope [target scope] |
72 | 71 | (or (= nil scope) ; nil implies global scope |
73 | | - (scope:equal target) |
| 72 | + (scope:equal target) |
74 | 73 | (vim.treesitter.is_ancestor scope target))) |
75 | 74 |
|
76 | 75 | (fn get-node-text [node buffer meta] |
|
81 | 80 | base-text))) |
82 | 81 |
|
83 | 82 | (fn get-completions-for-query [query] |
| 83 | + ;; To avoid getting an invalid node when calling M.get-completions-at-cursor, ensure |
| 84 | + ;; that the buffer is parsed. |
| 85 | + ;; See the note for `:he treesitter.get_node` and `:he languagetree`. |
| 86 | + (ts.parse!) |
84 | 87 | (let [buffer (vim.api.nvim_get_current_buf) |
85 | | - cursor-node (vim.treesitter.get_node) |
| 88 | + cursor-node (vim.treesitter.get_node) |
86 | 89 | (row _) (unpack (vim.api.nvim_win_get_cursor 0)) |
87 | 90 | scope-captures (query:iter_captures (cursor-node:root) buffer 0 row) |
88 | 91 | scopes (extract-scopes query scope-captures) |
89 | | - captures (query:iter_captures (cursor-node:root) buffer 0 row) |
| 92 | + captures (query:iter_captures (cursor-node:root) buffer 0 row) |
90 | 93 | results []] |
91 | 94 |
|
92 | 95 | (each [id n meta captures] |
|
112 | 115 | Arguments: |
113 | 116 | - ts-lang: tree-sitter grammar language |
114 | 117 | - cmpl-resource: query file resource path (queries/<cmpl-resource>/cmpl.scm) |
115 | | - |
| 118 | +
|
116 | 119 | Returns: |
117 | 120 | - deduplicated array of strings" |
118 | 121 | (let [query (get-completion-query ts-lang cmpl-resource)] |
|
124 | 127 | "Return function which filters words starting with prefix" |
125 | 128 | (let [sanitized-prefix (string.gsub (or prefix "") "%%" "%%%%") |
126 | 129 | prefix-pattern (.. "^" sanitized-prefix) |
127 | | - prefix-filter (fn [s] (string.match s prefix-pattern))] |
128 | | - (fn [list] |
| 130 | + prefix-filter (fn [s] (string.match s prefix-pattern))] |
| 131 | + (fn [list] |
129 | 132 | (a.filter prefix-filter list)))) |
130 | 133 |
|
131 | 134 | M |
0 commit comments