Skip to content

Commit

Permalink
fix(mongo): Map js filetype to javascript and add mappings
Browse files Browse the repository at this point in the history
  • Loading branch information
kristijanhusak committed Aug 24, 2024
1 parent 0f51d8d commit 2f34487
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 1 deletion.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ If there are duplicate connection names from same source, warning will be shown

## Settings

An overview of all settings and their default values can be found at `:help vim-dadbod-ui`.
An overview of all settings and their default values can be found at `:help vim-dadbod-ui`.

### Table helpers
Table helper is a predefined query that is available for each table in the list.
Expand Down Expand Up @@ -290,6 +290,7 @@ let g:db_ui_disable_mappings = 1 " Disable all mappings
let g:db_ui_disable_mappings_dbui = 1 " Disable mappings in DBUI drawer
let g:db_ui_disable_mappings_dbout = 1 " Disable mappings in DB output
let g:db_ui_disable_mappings_sql = 1 " Disable mappings in SQL buffers
let g:db_ui_disable_mappings_javascript = 1 " Disable mappings in Javascript buffers (for Mongodb)
```

## Toggle showing postgres views in the drawer
Expand Down
4 changes: 4 additions & 0 deletions autoload/db_ui.vim
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,10 @@ function! s:dbui.populate_schema_info(db) abort
let a:db.quote = get(scheme_info, 'quote', 0)
let a:db.default_scheme = get(scheme_info, 'default_scheme', '')
let a:db.filetype = get(scheme_info, 'filetype', db#adapter#call(url, 'input_extension', [], 'sql'))
" Properly map mongodb js to javascript
if a:db.filetype ==? 'js'
let a:db.filetype = 'javascript'
endif
endfunction

" Resolve only urls for DBs that are files
Expand Down
10 changes: 10 additions & 0 deletions doc/dadbod-ui.txt
Original file line number Diff line number Diff line change
Expand Up @@ -645,6 +645,16 @@ g:db_ui_disable_mappings_sql
If this is set to `1`, no default mappings for SQL buffers
are defined.

Default value: `0`

*g:db_ui_disable_mappings_javascript*
g:db_ui_disable_mappings_javascript
If this is set to `1`, no default mappings for Javascript buffers
are defined.
Note that these mappings are set only when buffer is created
with vim-dadbod-ui, to not interfere with default javascript
behavior.

Default value: `0`

*g:db_ui_bind_param_pattern*
Expand Down
8 changes: 8 additions & 0 deletions ftplugin/javascript.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
if get(g:, 'db_ui_disable_mappings', 0) || get(g:, 'db_ui_disable_mappings_javascript', 0) || get(b:, 'dbui_db_key_name', '') == ''
finish
endif

call db_ui#utils#set_mapping('<Leader>W', '<Plug>(DBUI_SaveQuery)')
call db_ui#utils#set_mapping('<Leader>E', '<Plug>(DBUI_EditBindParameters)')
call db_ui#utils#set_mapping('<Leader>S', '<Plug>(DBUI_ExecuteQuery)')
call db_ui#utils#set_mapping('<Leader>S', '<Plug>(DBUI_ExecuteQuery)', 'v')
1 change: 1 addition & 0 deletions plugin/db_ui.vim
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ let g:db_ui_disable_mappings = get(g:, 'db_ui_disable_mappings', 0)
let g:db_ui_disable_mappings_dbui = get(g:, 'db_ui_disable_mappings_dbui', 0)
let g:db_ui_disable_mappings_dbout = get(g:, 'db_ui_disable_mappings_dbout', 0)
let g:db_ui_disable_mappings_sql = get(g:, 'db_ui_disable_mappings_sql', 0)
let g:db_ui_disable_mappings_javascript = get(g:, 'db_ui_disable_mappings_javascript', 0)
let g:db_ui_table_helpers = get(g:, 'db_ui_table_helpers', {})
let g:db_ui_auto_execute_table_helpers = get(g:, 'db_ui_auto_execute_table_helpers', 0)
let g:db_ui_show_help = get(g:, 'db_ui_show_help', 1)
Expand Down

0 comments on commit 2f34487

Please sign in to comment.