Neovim - How to filter out text snippets from nvim-lspconfig + nvim-cmp - neovim

I'm using NeoVim with autocomplete using nvim-lspconfig and nvim-cmp. I would like to know if there's a way of filtering out text feeds from the autocompletion menu, so that they don't appear in the contextual menu:

In your setup you can exclude any kind if suggestions thanks to this merged PR.
What is happening is the function "entry_filter" is getting called whenever a suggestion for nvim_lsp is being made. in it we return false if the entry is of the kind "text".
local cmp = require "cmp"
cmp.setup {
...
sources = cmp.config.sources({
-- Dont suggest Text from nvm_lsp
{ name = "nvim_lsp",
entry_filter = function(entry, ctx)
return require("cmp").lsp.CompletionItemKind.Text ~= entry:get_kind()
end },
})
}

Check out nvim-cmp sources list and remove whatever source you don't want to use. Text is quite probably coming from buffer:
cmp.setup({
...
sources = cmp.config.sources({
{ name = 'buffer' }, -- <- remove
{ name = 'nvim_lsp' },
...
})
})

Related

How to select symbols onWorkspaceSymbol

I am developing an extension for visual studio code using language server protocol, and I am including the support for "Go to symbol in workspace". My problem is that I don't know how to select the matches...
Actually I use this function I wrote:
function IsInside(word1, word2)
{
var ret = "";
var i1 = 0;
var lenMatch =0, maxLenMatch = 0, minLenMatch = word1.length;
for(var i2=0;i2<word2.length;i2++)
{
if(word1[i1]==word2[i2])
{
lenMatch++;
if(lenMatch>maxLenMatch) maxLenMatch = lenMatch;
ret+=word1[i1];
i1++;
if(i1==word1.length)
{
if(lenMatch<minLenMatch) minLenMatch = lenMatch;
// Trying to filter like VSCode does.
return maxLenMatch>=word1.length/2 && minLenMatch>=2? ret : undefined;
}
} else
{
ret+="Z";
if(lenMatch>0 && lenMatch<minLenMatch)
minLenMatch = lenMatch;
lenMatch=0;
}
}
return undefined;
}
That return the sortText if the word1 is inside the word2, undefined otherwise. My problem are cases like this:
My algorithm see that 'aller' is inside CallServer, but the interface does not mark it like expected.
There is a library or something that I must use for this? the code of VSCode is big and complex and I don't know where start looking for this information...
VSCode's API docs for provideWorkspaceSymbols() provide the following guidance (which I don't think your example violates):
The query-parameter should be interpreted in a relaxed way as the editor will apply its own highlighting and scoring on the results. A good rule of thumb is to match case-insensitive and to simply check that the characters of query appear in their order in a candidate symbol. Don't use prefix, substring, or similar strict matching.
These docs were added in response to this discussion, where somebody had very much the same issue as you.
Having a brief look at VSCode sources, internally it seems to use filters.matchFuzzy2() for the highlighting (see here and here). I don't think it's exposed in the API, so you would probably have to copy it if you wanted the behavior to match exactly.

How to add own tags using the tagify plugin, 'Mix text & tags' in particular

I'm creating an input field mixed with tags and inputs using the tagify plugin- section-mix- (see: https://yaireo.github.io/tagify/#section-mix).
The problem is:
Note that tags can only be created if the value matches any of the whitelisted item's value.
I want to add them myself by hitting enter just as in the other examples in the link. Any idea how to solve this with tagify?
HTML
<textarea name='mix'>#cartman and #kyle do not know #homer who is #lisa</textarea>
JAVASCRIPT
var input = document.querySelector('[name=mix]'),
// init Tagify script on the above inputs
tagify = new Tagify(input, {
mode : 'mix', // <-- Enable mixed-content
pattern : /#/, // <-- Tag words which start with # (can be a String instead of Regex)
whitelist : [
{
value: 'Homer'
}
],
dropdown : {
enabled : 1
}
})
var whitelist_2 = ['Homer', 'Marge', 'Bart', 'Lisa', 'Maggie', 'Mr. Burns', 'Ned', 'Milhouse', 'Moe'];
// A good place to pull server suggestion list accoring to the prefix/value
tagify.on('input', function(e){
var prefix = e.detail.prefix;
if( prefix == '#' )
tagify.settings.whitelist = whitelist_2;
if( e.detail.value.length > 1 )
tagify.dropdown.show.call(tagify, e.detail.value);
}
Tagify now supports creating new tags in mix-mode as of version 3.4.0
See tagify's example page
UPDATE 24 FEB, 2020
Currently only tags without spaces can be added due to unresolved complexity in the implementation of how adding new tags in mix-mode works. I will address this soon.

How to overlay a cq widget so it is also available in SiteAdmin

The CQ.tagging.TagInputField provided two configuration parameter which won't work in combination:
tagsBasePath
namespaces
Using the OOTB facebook tags as example, I want to restric the dialog to only display the Favorite Teams. The Structure is this:
So I set tagBasePath to /etc/tags/facebook and namespaces to [favorite_teams]. This does what it is supposed to do and only shows the two teams in the dialog. But when you click on it, a JavaScript exceptions is thrown. The problem lies in the following method defined in /libs/cq/tagging/widgets/source/CQ.tagging.js
CQ.tagging.parseTag = function(tag, isPath) {
var tagInfo = {
namespace: null,
local: tag,
getTagID: function() {
return this.namespace + ":" + this.local;
}
};
// parse tag pattern: namespace:local
var colonPos = tag.indexOf(isPath ? '/' : ':');
if (colonPos > 0) {
// the first colon ":" delimits a namespace
// don't forget to trim the strings (in case of title paths)
tagInfo.namespace = tag.substring(0, colonPos).trim();
tagInfo.local = tag.substring(colonPos + 1).trim();
}
return tagInfo;
};
It does not respect the configurations set on the widget and returns a tagInfo where the namespace is null. I then overlayed the method in my authoring JavaScripts, but this is of course not working in the SiteAdmin as my custom JS are not included.
So, do I really have to overwrite the CQ.tagging.js below libs or can I somehow inject my overlay into the SiteAdmin so the PageProperties Dialog opened from there works as well?
UPDATE: I had a chat with Adobe support regarding this and it was pointed out that if you use tagsBasePath you need to place it somewhere else than below /etc/tags. But this won't work as well as the TagListServlet will return no tags as /etc/tags is also fixed in the TagManager as the tagsBasePath. I now overwrite the above mentioned js at its location, being well aware that I need to check it if we install a hotfix or an update. Is someone has a more elegant solution I'd be still thankful.

CodeMirror: xml attribute completion, add = automatically

Is it possible in CodeMirror to automatically add the = sign when autocompleting an attribute? Specifically on ctrl-space (like in the xml completion demo) when you almost finished typing the attribute's name and want to complete it using ctrl space...
Thanks,
Jaap
Try this
http://jsfiddle.net/aljordan82/h5f67/
extraKeys: {
"Ctrl-Space": function(){
var cursor = editor.getCursor();
var token = editor.getTokenTypeAt(cursor);
//console.log(token)
if (token == "attribute"){
editor.replaceSelection("=" , "end");
}
}
}

KRL and Yahoo Local Search

I'm trying to use Yahoo Local Search in a Kynetx Application.
ruleset avogadro {
meta {
name "yahoo-local-ruleset"
description "use results from Yahoo local search"
author "randall bohn"
key yahoo_local "get-your-own-key"
}
dispatch { domain "example.com"}
global {
datasource local:XML <- "http://local.yahooapis.com/LocalSearchService/V3/localsearch";
}
rule add_list {
select when pageview ".*" setting ()
pre {
ds = datasource:local("?appid=#{keys:yahoo_local()}&query=pizza&zip=#{zip}&results=5");
rs = ds.pick("$..Result");
}
append("body","<ul id='my_list'></ul>");
always {
set ent:pizza rs;
}
}
rule add_results {
select when pageview ".*" setting ()
foreach ent:pizza setting pizza
pre {
title = pizza.pick("$..Title");
}
append("#my_list", "<li>#{title}</li>");
}
}
The list I wind up with is
. [object Object]
and 'title' has
{'$t' => 'Pizza Shop 1'}
I can't figure out how to get just the title. It looks like the 'text content' from the original XML file turns into {'$t' => 'text content'} and the '$t' give problems to pick().
When XML datasources and datasets get converted into JSON, the text value within an XML node gets assigned to $t. You can pick the text of the title by changing your pick statement in the pre block to
title = pizza.pick("$..Title.$t");
Try that and see if that solves your problem.
Side notes on things not related to your question to consider:
1) Thank you for sharing the entire ruleset, what problem you were seeing and what you expected. Made answering your question much easier.
2) The ruleset identifier should not be changed from what AppBuilder or the command-line gem generate for you. Your identifier that is currently
ruleset avogadro {
should look something more like
ruleset a60x304 {
3) You don't need the
setting ()
in the select statement unless you have a capture group in your regular expression
Turns out that pick("$..Title.$t") does work. It looks funny but it works. Less funny than a clown hat I guess.
name = pizza.pick("$..Title.$t");
city = pizza.pick("$..City.$t");
phone = pizza.pick("$..Phone.$t");
list_item = "<li>#{name}/#{city} #{phone}</li>"
Wish I had some pizza right now!