Fix #36 · megabug/codeql.nvim@5a70845 · GitHub
Skip to content

Commit 5a70845

Browse files
committed
1 parent 9212d89 commit 5a70845

6 files changed

Lines changed: 118 additions & 38 deletions

File tree

‎README.md‎

Lines changed: 3 additions & 2 deletions

‎ftdetect/ql.vim‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
11
au BufRead,BufNewFile *.ql setfiletype ql
22
au BufRead,BufNewFile *.qll setfiletype ql
33

4-
nnoremap qr :RunQuery<CR>
5-
nnoremap qp :QuickEvalPredicate<CR>
6-
nnoremap qe :QuickEval<CR>
7-
vnoremap qe :QuickEval<CR>

‎lua/codeql/config.lua‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ M.defaults = {
1616
group_by = "sink",
1717
context_lines = 3,
1818
},
19+
mappings = {
20+
run_query = { modes = { "n" }, lhs = "<space>qr", desc = "run query" },
21+
quick_eval = { modes = { "x", "n" }, lhs = "<space>qe", desc = "quick evaluate" },
22+
quick_eval_predicate = { modes = { "n" }, lhs = "<space>qp", desc = "quick evaluate enclosing predicate" },
23+
},
1924
}
2025

2126
M._config = M.defaults

‎lua/codeql/init.lua‎

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -123,26 +123,6 @@ function M.get_enclosing_predicate_position()
123123
end
124124
end
125125

126-
function M.get_current_position()
127-
local srow, scol, erow, ecol
128-
129-
if vim.fn.getpos("'<")[2] == vim.fn.getcurpos()[2] and vim.fn.getpos("'<")[3] == vim.fn.getcurpos()[3] then
130-
srow = vim.fn.getpos("'<")[2]
131-
scol = vim.fn.getpos("'<")[3]
132-
erow = vim.fn.getpos("'>")[2]
133-
ecol = vim.fn.getpos("'>")[3]
134-
135-
ecol = ecol == 2147483647 and 1 + vim.fn.len(vim.fn.getline(erow)) or 1 + ecol
136-
else
137-
srow = vim.fn.getcurpos()[2]
138-
scol = vim.fn.getcurpos()[3]
139-
erow = vim.fn.getcurpos()[2]
140-
ecol = vim.fn.getcurpos()[3]
141-
end
142-
143-
return { srow, scol, erow, ecol }
144-
end
145-
146126
function M.quick_evaluate_enclosing_predicate()
147127
local position = M.get_enclosing_predicate_position()
148128
if position then
@@ -151,11 +131,11 @@ function M.quick_evaluate_enclosing_predicate()
151131
end
152132

153133
function M.quick_evaluate()
154-
M.query(true, M.get_current_position())
134+
M.query(true, util.get_current_position())
155135
end
156136

157137
function M.run_query()
158-
M.query(false, M.get_current_position())
138+
M.query(false, util.get_current_position())
159139
end
160140

161141
function M.query(quick_eval, position)
@@ -334,6 +314,8 @@ function M.setup(opts)
334314
vim.cmd [[au BufEnter * if &ft ==# 'codeql_panel' | execute("lua require'codeql.panel'.apply_mappings()") | endif]]
335315
vim.cmd [[au BufEnter codeql://* lua require'codeql'.setup_archive_buffer()]]
336316
vim.cmd [[au BufReadCmd codeql://* lua require'codeql'.load_source_buffer()]]
317+
vim.cmd [[autocmd FileType ql lua require'codeql.util'.apply_mappings()]]
318+
337319
if require("codeql.config").get_config().format_on_save then
338320
vim.cmd [[autocmd FileType ql autocmd BufWrite <buffer> lua vim.lsp.buf.formatting()]]
339321
end

‎lua/codeql/queryserver.lua‎

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -206,16 +206,10 @@ function M.run_query(opts)
206206
}
207207

208208
local runQueries_callback = function(err, result)
209-
print("FOO", vim.inspect(result))
210209
if err then
211210
util.err_message "ERROR: runQuery failed"
212211
end
213212
if util.is_file(bqrsPath) then
214-
print(bqrsPath)
215-
print(dbPath)
216-
print(queryPath)
217-
print(opts.metadata["kind"])
218-
print(opts.metadata["id"])
219213
loader.process_results {
220214
bqrs_path = bqrsPath,
221215
bufnr = bufnr,
@@ -289,7 +283,6 @@ function M.run_query(opts)
289283
runQueries_params,
290284
runQueries_callback
291285
)
292-
print("RunQuery", last_rpc_result, last_rpc_msg_id)
293286
end
294287
end
295288

@@ -301,19 +294,16 @@ function M.run_query(opts)
301294
compileQuery_params,
302295
compileQuery_callback
303296
)
304-
print("CompileQuery", last_rpc_result, last_rpc_msg_id)
305297
end
306298

307299
function M.register_database(database)
308300
if not M.client then
309301
M.client = M.start_server()
310302
end
311303
config.database = database
312-
print("Database details:", vim.inspect(database))
313304
local resp = util.database_upgrades(
314305
config.database.datasetFolder .. "/" .. config.database.languages[1] .. ".dbscheme"
315306
)
316-
print(vim.inspect(resp.scripts))
317307
if resp ~= vim.NIL and #resp.scripts > 0 then
318308
util.database_upgrade(config.database.path)
319309
end

‎lua/codeql/util.lua‎

Lines changed: 106 additions & 0 deletions

0 commit comments

Comments
 (0)