make nvim-cmp not autoselect the 1st option - neovim

I'm using nvim-cmp as my completion engine, which is working fine, but would like to change the default behavior to disable the automatic selection of the first option. The reason is that, when the last word of a line has suggestions, pressing enter will apply the first suggestion instead of just inserting a newline.
For example, in haskell, typing
main = do<CR>
the do matches diso~ from luasnip, and is replaced by something like
main = 2022-12-05T12:50:34
I would prefer the suggestions to be visible but none of them selected until tab is pressed, and if none is selected then <CR> is just a newline. Is this possible?

Answering my own question, I found out that when using lsp-zero, the configuration has to be done there. The documention in advanced-usage.md provides the exact solution, which I'm posting here:
local lsp = require('lsp-zero')
lsp.preset('system-lsp') -- or recommended, or whatever...
lsp.setup_nvim_cmp({
preselect = 'none',
completion = {
completeopt = 'menu,menuone,noinsert,noselect'
},
})
lsp.setup()

First set completeopt=menu,preview,menuone,noselect to configure auto-completion menu.
Then you have to modify your cmp plugin configuration for mapping of CR key :
local cmp = require'cmp'
cmp.setup({
mapping = cmp.mapping.preset.insert({
['<CR>'] = cmp.mapping.confirm({ select = false }),
})
})
See cmp plugins documentation for further explanations about cmp.confirm option.

Related

VsCode Extension custom CompletionItem disables built-in Intellisense

I am working on a VsCode extension in that I want to provide custom snippets for code completion.
I know about the option of using snippet json files directly, however those have the limitation of not being able to utilize the CompletionItemKind property that determines the icon next to the completion suggestion in the pop-up.
My issue:
If I implement a simple CompletionItemProvider like this:
context.subscriptions.push(
vscode.languages.registerCompletionItemProvider(
{scheme:"file",language:"MyLang"},
{
provideCompletionItems(document: vscode.TextDocument, position: vscode.Position) {
let item = new vscode.CompletionItem('test');
item.documentation = 'my test function';
item.kind = vscode.CompletionItemKind.Function;
return [item];
}
}
)
)
then the original VsCode IntelliSense text suggestions are not shown anymore, only my own. Should I just return a kind of an empty response, like
provideCompletionItems(document: vscode.TextDocument, position: vscode.Position) {
return [null|[]|undefined];
}
the suggestions appear again as they should. It seems to me that instead of merging the results of the built-in IntelliSense and my own provider, the built-in ones get simply overridden.
Question:
How can I keep the built-in IntelliSense suggestions while applying my own CompletionItems?
VsCode Version: v1.68.1 Ubuntu
I seem to have found the answer for my problem, so I will answer my question.
Multiple providers can be registered for a language. In that case providers are sorted
by their {#link languages.match score} and groups of equal score are sequentially asked for
completion items. The process stops when one or many providers of a group return a
result.
My provider seems to provide results that are just higher scored than those of IntelliSense.
Since I didn't provide any trigger characters, my CompletionItems were comteping directly with the words found by the built-in system by every single pressed key and won.My solution is to simply parse and register the words in my TextDocument myself and extend my provider results by them. I could probably just as well create and register a new CompletionItemProvider for them if I wanted to, however I decided to have a different structure for my project.

Is there anyway to check inactive terminalEditors in when arg in keybindings.json in VScode?

I want to createTerminalEditor if there is no terminalEditor opened yet.
Note: I'm talking about terminalEditor and not terminal.
So, I'm looking for a when arg which says something like editorAlreadyExists != terminalEditor, just like there is activeEditor which aceepts string of terminalEditor.
Is there anyway to achieve this?
Here is activeEditor example for reference, but I want to check if terminalEditor exists in all the already opened editors, not just a activeEditor.
{
"key": "ctrl+`",
"command": "workbench.action.createTerminalEditor",
"when": "activeEditor != terminalEditor"
},
I see that there is a when clause for:
terminalEditorFocus: true/false
which doesn't look like it would help except for the fact that it isn't in the list (via Developer: Inspect Context Keys) at all when there is no terminal editor open. So I thought maybe there was a keybinding when clause that could exploit this. But I tried all kinds of thing, like whether it was null or undefined or the empty string or neither true nor false, etc. but nothing worked. I think if the key terminalEditorFocus doesn't exist, then nothing at all is delivered to the keybinding resolver and it always fails.
You could file an issue asking for a specific terminalEditorExists sort of when clause.
There will be another way. There is a presently experimental api to access all the open tabs. See proposed api. So you could write an extension that checks all the open tabs and fires the workbench.action.createTerminalEditor command if none are a terminalEditor. It works right now in the Insiders Build, but when it will go final I don't know - it seems pretty solid now. Issue: Tab Model API.
const tabs = vscode.window.tabs;
const openTerminalEditor = tabs.some(tab => tab.viewId === 'terminalEditor'); // true/false
Then you could either set your own context key with setContext or run the command.

Using Chrome Dev Tools Code Folding Shortcuts

On the Settings > Preferences > Source we can enable Code Folding on the Chrome Dev. But I didn't find a way to use keyboard shortcuts to, eg. collapse all, etc. Did look for in the Shortcuts section window and in the Full Listings also, but no success. I'm assuming we can't do it on the current version. In case someone knows about it, I'll be very happy to know it too.
There's no such hotkey so try suggesting this feature on https://crbug.com.
Meanwhile you can add it manually:
make sure "code folding" is enabled in devtools settings (in the "Sources" group)
run this code in devtools-on-devtools (see the instruction below)
[
['Shift-Ctrl-[', 'fold'],
['Shift-Ctrl-]', 'unfold'],
['Shift-Ctrl--', 'foldAll'],
['Shift-Ctrl-=', 'unfoldAll'],
].forEach(([key, cmd]) => {
CodeMirror.keyMap['devtools-common'][key] = CodeMirror.commands[cmd];
});
close devtools-on-devtools
This will last only for the current devtools instance.
For convenience you can save the code in snippets and run it later from there or by typing the snippet name in the commands palette (Ctrl-P or Cmd-P hotkey).
How to open devtools-on-devtools:
Open devtools first and switch its Dock side in the menu to a detached (floating) window
in the now detached devtools press CtrlShifti or ⌘⌥i on MacOS,
which will open devtools-on-devtools in a new window
The top answer is great, but chrome devtools has been updated since to use CodeMirror 6, which requires a codeMirror instance to be passed to the functions:
CodeMirror.commands.foldAll();
Uncaught TypeError: Cannot read properties of undefined (reading 'operation')
at CodeMirror.commands.foldAll (foldcode.js:105:8)
at <anonymous>:1:21
line 104-109 from foldcode.js:
CodeMirror.commands.foldAll = function(cm) {
cm.operation(function() {
for (var i = cm.firstLine(), e = cm.lastLine(); i <= e; i++)
cm.foldCode(CodeMirror.Pos(i, 0), null, "fold");
});
};
I could solve it by debugging a codemirror event to save the cm instance as a global variable (temp1), but I would appreciate if someone could have a better solution to this that can be automated.
Edit: I found the codeMirror instance at document.getElementsByClassName("CodeMirror")[1].CodeMirror, so a working solution is:
CodeMirror.commands.foldAll(document.getElementsByClassName("CodeMirror")[1].CodeMirror)
the shortcut setting still doesn't seem to work though.
(with
CodeMirror.keyMap["devtools-common"]["Ctrl-k"]=function()
{let {CodeMirror:instance}=
document.getElementsByClassName("CodeMirror")[1];
CodeMirror.commands.foldAll(instance);
};
)
Edit 2: oh, it just needed capital K, so "Ctrl-K". Now the shortcut works too. hurrah
btw i've commented on the folding feature's thread on chromium bugtracker to include this, because it is incredibly useful for skimming files while editing/reading. No response yet, idk if anyone's even paying attention to comments there anymore:
https://bugs.chromium.org/p/chromium/issues/detail?id=328431
CodeMirror 6 supports the folding shortcuts natively (per foldKeymap):
Ctrl-Shift-[ (Cmd-Alt-[ on macOS): Fold the lines that are selected, if possible.
Ctrl-Shift-] (Cmd-Alt-] on macOS): Unfold folded ranges on selected lines.
Ctrl-Alt-[: Fold all top-level foldable ranges.
Ctrl-Alt-]: Unfold all folded code.

decreaseIndentPattern has no effect

I am trying to create a TextMate bundle for a new language but am having issues with the decreaseIndentPattern. It seems to have no effect whatsoever, even with a trivial example:
increaseIndentPattern = 'start';
decreaseIndentPattern = 'end';
I have set the scope correctly and the other settings in the same file do work (including the increaseIndentPattern). Am I missing something?
Found out that to enable indentation correction on text based files (my scope starts with text), the following is also required:
disableIndentCorrections = :false;

AngularJS - binding input file scope to a different scope

Wasn't sure how to properly title my question, I guess in my case it can also be titled "DOM manipulation not being detected by the scope", but it all depends on the approach of my problem.
To start off, I followed an official example on AngularJS main website with the Projects app which connects with Mongolab. The only difference is I want to add a file input, that reads file name and its lastModifiedDate properties and then applies those values to my form. To make file input work I followed this example here.
I made it work, but the problem is that when values get applied to my form scope is not picking up the changes.
I am doing DOM manipulation in my .apply() function and using $compile too, but something is missing. Or perhaps there's an easier way altogether without doing DOM manipulation?
Here's what I have so far, please take a look at this plunker - http://plnkr.co/edit/mkc4K4?p=preview
(Just click on the plus sign icon to add new entry, then try choosing a file.)
You need to add a watch statement in the CreateCtrl
function CreateCtrl($scope, $location, Movie) {
$scope.inputfile = {};
$scope.movie = {};
$scope.$watch('inputfile.file', function(value){
$scope.movie.filename = value ? value.name : '';
$scope.movie.dateadded = value ? value.lastModifiedDate : '';
})
$scope.save = function() {
Movie.save($scope.movie, function(movie) {
$location.path('/edit/' + movie._id.$oid);
});
};
}
Demo: Sample