crystal-ameba / vscode-crystal-ameba Goto Github PK
View Code? Open in Web Editor NEWAmeba extension for Visual Studio Code
Home Page: https://marketplace.visualstudio.com/items?itemName=veelenga.crystal-ameba
Ameba extension for Visual Studio Code
Home Page: https://marketplace.visualstudio.com/items?itemName=veelenga.crystal-ameba
Currently when there is an issue with the extension finding the Ameba executable (or after you've just installed Ameba as a dependency) the extension spams the notification bar with "... is not recognised" on Windows or "... ameba: not found" for Linux. Despite the path being later available in the desired location, the extension still complains and a window reload is required for the extension to work. It would be nice if there was a command which simply restarted the extension to do this.
There are also situations where the environment I'm working in doesn't use Ameba, to which the former issue arises again... A command to disable the extension in that workspace (or at least just turn it off) would be highly appreciated.
Thanks for the time you've put towards a linter for Crystal!
The issue I'm having is in the title, can't get this plugin to work with the described version. Is there a minimum version of vscode required? (just seen the latest version of vscode is 1.32, will try and update if not)
I'm able to install ameba via home-brew and is working from the command line correctly ๐
Environment
Crystal Version 0.27.2
OSX Version Mojave 10.14
I run my VS Code in Windows and using Crystal tools via wsl interface.
Running VS Code in WSL mode is not feasible for me since my project has a large amount of files that make VS Code WSL mode consumes a lot of memory and CPU to watch those files (yes even if those files are explicitly ignored).
Is there anyway to set the absolute path for ameba (like in the VS Code Crystal extension) so I can prefix the command path with wsl
to make it works in windows?
I tried to create an ameba.bat with this content, but it doesn't seem to work:
wsl /usr/bin/ameba %*
For example if I write this simple code:
# TODO: Write documentation for `Web`
module Web
require "kemal"
VERSION = "0.1.0"
get "/" do
"Hello World!"
end
Kemal.run
end
It gives a:
syntax error in 'STDIN:4:3': can't require inside type declarations
on another windows on save only, so you have to undo the save and correct.
The extension is missing the icon, using the default - generic - instead.
While browsing through the source code I noticed that the getConfig
method returns onSave: true
.
Would it be possible to add a configuration so that we can change this settings to lint while writing the code instead of only checking after saving ?
Similar to ruby-lsp
's behaviour with Rubocop
After installing the extension this warning appeared /bin/sh: 1: ameba: not found
. I'm using ameba as a dependency of my project.
Crystal 0.34.0 [4401e90f0] (2020-04-06)
LLVM: 8.0.0
Default target: x86_64-unknown-linux-gnu
Shards 0.10.0 [4091ac5] (2020-04-06)
I was getting the message "Ameba: failed to parse JSON response."
Inspecting in the console the error was:
Ameba: failed parsing JSON: SyntaxError: Unexpected token 'E', "Error: Una"... is not valid JSON
Then checking the STDOUT of the command I got the following:
Error: Unable to load config file: Config file does not exist /my/path/to/.ameba.yml
Searching a bit, I see the new Ameba 1.5.0 raises exception when --config
argument is used but file (.ameba.yml
) does not exist. Apparently this did not happen in previous versions.
Checking how the extension treats the configuration file, I found this condition that I don't quite understand the sense of.
vscode-crystal-ameba/src/ameba.ts
Lines 35 to 38 in 3ea5d00
I think it should be checked if that file exists and not the length of filename.
Possible solution would be:
diff --git a/src/ameba.ts b/src/ameba.ts
index 56b5b43..60474ec 100644
--- a/src/ameba.ts
+++ b/src/ameba.ts
@@ -1,5 +1,6 @@
import { exec } from 'child_process';
import * as path from 'path';
+import { existsSync } from 'fs';
import {
commands,
Diagnostic,
@@ -32,10 +33,9 @@ export class Ameba {
}
const args = [this.config.command, document.fileName, '--format', 'json'];
- if (this.config.configFileName.length) {
- const dir = workspace.getWorkspaceFolder(document.uri)!.uri.fsPath;
- args.push('--config', path.join(dir, this.config.configFileName));
- }
+ const dir = workspace.getWorkspaceFolder(document.uri)!.uri.fsPath;
+ const configFile = path.join(dir, this.config.configFileName);
+ if (existsSync(configFile)) args.push('--config', configFile);
const task = new Task(document.uri, token => {
const proc = exec(args.join(' '), (err, stdout, stderr) => {
Ameba::Config.each_config_path
already checks if the config file exists in the current directory as well as in the user's home. Perhaps the better approach is to remove this from the extension and let Ameba handle it itself.
Hello ๐
I wanted to install Ameba globally on my system but after doing so the extension is not able to execute the command anymore for some reason.
I've moved the bin/ameba
executable inside my $HOME/.asdf/plugins/crystal/bin
directory and added the directory to my PATH
by writing export PATH="$HOME/.asdf/plugins/crystal/bin:$PATH"
in my .zshrc
config file.
When I run the command form a terminal everything works fine
โ fullstack-challenges-crystal git:(master) โ ameba
Inspecting 11 files
..F........
00-Setup/00-Demo/src/demo.cr:4:3 [Correctable]
[C] Style/RedundantReturn: Redundant `return` detected
> return Math::PI * radius**2
^-------------------------^
Finished in 15.31 milliseconds
11 inspected, 1 failure
But I try to run the extension I have an error message that says
I've had a look at https://github.com/crystal-ameba/vscode-crystal-ameba/blob/master/src/configuration.ts and I don't see any reason it would be able to run the command.
I do not have a local bin/ameba
file so the command should just be ameba
which works when I run it as shown above.
Would you have any idea as to what the problem might be ?
Here's a photo:
All of this highlighting is because the cyclomatic complexity warning. I think two things should be changed:
Upon install this extension, I receive the following error:
Error: Invalid arguments
at new f (/home/exarch/Downloads/VSCode-linux-x64/VSCode-linux-x64/resources/app/out/vs/workbench/api/node/extensionHostProcess.js:97:15156)
at /home/exarch/.vscode/extensions/veelenga.crystal-ameba-0.1.0/out/ameba.js:56:39
at Array.forEach (<anonymous>)
at /home/exarch/.vscode/extensions/veelenga.crystal-ameba-0.1.0/out/ameba.js:53:35
at ChildProcess.exithandler (node:child_process:417:5)
at ChildProcess.emit (node:events:513:28)
at maybeClose (node:internal/child_process:1121:16)
at Socket.<anonymous> (node:internal/child_process:479:11)
at Socket.emit (node:events:513:28)
at Pipe.<anonymous> (node:net:757:14)
$onExtensionRuntimeError @ mainThreadExtensionService.ts:82
This happens in the latest version of Visual Studio Code, Code OSS, and Codium.
VSCode shows problems, which are ignored in my .ameba.yml
config file. When i run ameba from command line, all is OK (no problems).
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.