How do I change the formatter line length with neovim lsp dart? - flutter

I'm running nvim using the built in LSP (via the superb AstroVim) to develop dart and flutter.
Loving everything, except how the lsp formatting (which formats on save) is wrapping my lines at 80 characters.
I can see how the dart command line formatter supports
--line-length=<value>
My question: how do I include that parameter to the lsp in the
lua vim.lsp.buf.formatting()
command in order to format at a longer line length.
PS. yes I'm fully aware of the religious war over line length.
PPS. I've tried this in my AstroVim user config, but it doesn't seem to work
["server-settings"] = {
dartls = {
settings = {
["line-length"] = 120
}
}
}

With AstroNvim, you could add options for your LSP configuration with lsp.server-settings.<lsp> option.
Replace <lsp> by the name of the LSP server used for dart/flutter and add option for line-length (options could be a table or a function). See examples in https://github.com/AstroNvim/AstroNvim/tree/main/lua/configs/lsp/server-settings and https://github.com/AstroNvim/AstroNvim/blob/main/lua/user_example/init.lua
According to dartls documentation, the correct configuration should be :
["server-settings"] = {
dartls = {
settings = {
dart = {
lineLength = 120
}
}
}
}

Related

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

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' },
...
})
})

How to resolve "unresolved import" in Rust when using VS Code?

I'm fairly new to rust and have been following the official book that they provide on their site. During chapter 2 they tell you to import a "Rand" cargo which I did. However, when I try to run my code directly through VS Code I get an error saying "unresolved import rand". When I run it through command prompt, everything works fine. I've already tried every solution suggested here: https://github.com/rust-lang/rls-vscode/issues/513 and nothing seemed to have worked. Extensions that I'm using:
Better TOML
Cargo
Code Runner
Rust (rls)
Rust Assist
vsc-rustfmt
vscode-rust-syntax
Has anyone else ran into a similar problem or a know a solution? Thank you!
Edit: My Cargo.TOML looks like this:
[package]
name = "guessing_game"
version = "0.1.0"
authors = ["Name <MyNameHere#gmail.com>"]
edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
rand = "0.6.0"
Edit 2: my main.rs file looks like this:
use rand::Rng;
use std::io;
use std::cmp::Ordering;
fn main()
{
println!("Guess the number!");
let secret_number = rand::thread_rng().gen_range(1, 101);
loop
{
println!("Please input your guess!");
let mut guess = String::new();
io::stdin().read_line(&mut guess).expect("Failed to read line!");
let guess: u32 = match guess.trim().parse()
{
Ok(num) => num,
Err(_) => continue,
};
println!("Your guess {}", guess);
match guess.cmp(&secret_number)
{
Ordering::Less => println!("Too small!"),
Ordering::Greater => println!("Too big!"),
Ordering::Equal =>
{
println!("You win!");
break;
}
}
}
}
Got a fix!
In VSC, select Extensions, select the Code Runner extension, click the little gear symbol and select Extension Settings. It's the Code-runner: Executor Map setting that needs to be changed. Click the 'Edit in settings.json' link.
Add the following to the file:
"code-runner.executorMap": {
"rust": "cargo run # $fileName"
}
If you already have content in the settings.json file then remember to add a comma to the line above and put your edit inside the outermost curly braces, e.g.
{
"breadcrumbs.enabled": true,
"code-runner.clearPreviousOutput": true,
"code-runner.executorMap": {
"rust": "cargo run # $fileName"
}
}
This tells Code Runner to use the 'cargo run' command, instead of 'rustc'
This fix came from this question on stackoverflow.

Comment lines in .sln file

I'm trying to comment some lines in .sln file temporarly, but I receive error:
"The selected file is a solution file, but appears to be corrupted and cannot be opened"
According to this blog comments are done by "#", but when I comment out every line in GlobalSection (section about Team Foundation Server source control binding) I get above error. Is there any other way to comment out lines in .sln ?
EDIT - section of which I want to comment out:
GlobalSection(TeamFoundationVersionControl) = preSolution
SccNumberOfProjects = 2
SccEnterpriseProvider = {4BA58AB2-18FA-4D8F-95F4-32FFDF27D184C}
SccTeamFoundationServer = http://oxy:8080/tfs/projects
SccLocalPath0 = .
SccProjectUniqueName1 = Accounts\\Accounts.vbproj
SccProjectName1 = Accounts
SccLocalPath1 = Accounts
EndGlobalSection
I tried this, but not working:
# GlobalSection(TeamFoundationVersionControl) = preSolution
# SccNumberOfProjects = 2
# SccEnterpriseProvider = {4BA58AB2-18FA-4D8F-95F4-32FFDF27D184C}
# SccTeamFoundationServer = http://oxy:8080/tfs/projects
# SccLocalPath0 = .
# SccProjectUniqueName1 = Accounts\\Accounts.vbproj
# SccProjectName1 = Accounts
# SccLocalPath1 = Accounts
# EndGlobalSection
P.S.: I tried a single line comment using "#" - that works. And removing whole section also works. But I don't want to delete It, just comment It.
I don't think there is an official definition of comments in the .sln file. It depends on the parser.
In principle, a .sln file is a declarative file, based on the keywords (ProjectSection, EndGlobalSection) and the end-line char. I don't see a uniform format description.
MSBuild
So we don't know how Visual Studio reads the .sln file, but you can see in the msbuild code that any line that doesn't start with one of the const words will not enter to the object:
while ((str = ReadLine()) != null)
{
if (str.StartsWith("Project(", StringComparison.Ordinal))
{
ParseProject(str);
}
else if (str.StartsWith("GlobalSection(NestedProjects)", StringComparison.Ordinal))
{
ParseNestedProjects();
}
else if (str.StartsWith("GlobalSection(SolutionConfigurationPlatforms)", StringComparison.Ordinal))
{
ParseSolutionConfigurations();
}
else if (str.StartsWith("GlobalSection(ProjectConfigurationPlatforms)", StringComparison.Ordinal))
{
rawProjectConfigurationsEntries = ParseProjectConfigurations();
}
else if (str.StartsWith("VisualStudioVersion", StringComparison.Ordinal))
{
_currentVisualStudioVersion = ParseVisualStudioVersion(str);
}
else
{
// No other section types to process at this point, so just ignore the line
// and continue.
}
}
Visual Studio
According to this blog comments are done by "#"
That is not accurate. You can add lines with any text where you want, without the #, and the file will stay correct.
So, in Visual Studio, you currently don't know the official format, but you need to "break" the current format.
You can try changing the keywords, such as adding a letter to them at the beginning.
From what I've tried, special characters (such as #, %) don't break your keywords.

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 can i use Orion as the web editor in Xtext?

I tried to search how i can change the web editor for my Xtext project. But it seems there is missing some documentation.
My question is how can I change the default web editor ace to my prefered editor orion ?
you need to do two things
adapt the workflow to use orion webSupport = { framework = "Orion"} (best done before first generation since generate once files will not be overriden)
since there is no webjar for orion you need to download/unpack it manually and or separately depending on your build system.
you may have a look at the Yeoman generator-xtext (https://github.com/itemis/generator-xtext) which allows you to create a gradle + xtext + web + orion project.
Workflow {
component = XtextGenerator {
...
language = StandardLanguage {
name = "org.xtext.example.mydsl.MyDsl"
fileExtensions = "mydsl"
serializer = {
generateStub = false
}
validator = {
// composedCheck = "org.eclipse.xtext.validation.NamesAreUniqueValidator"
}
webSupport = {
framework = "Orion"
}
}
}
}