GithubHelp home page GithubHelp logo

zargony / atom-language-rust Goto Github PK

View Code? Open in Web Editor NEW
116.0 10.0 33.0 161 KB

Rust language support in Atom - LOOKING FOR MAINTAINER, see #144

License: MIT License

CoffeeScript 99.00% CSS 1.00%
atom rust

atom-language-rust's Introduction

Rust language support in Atom

Adds syntax highlighting and snippets to Rust files in Atom.

Install

Install the package language-rust in Atom (Preferences->Packages) or Atom's package manager from a shell:

$ apm install language-rust

Bugs

Grammar rules were written from scratch. They seem to work for most cases. However there are most certainly still a few cases that result in wrong syntax highlighting. Feel free to fix it and send a pull request, or open an issue to report it.

Links

  • Rust -- a safe, concurrent, practical language
  • Atom -- a hackable text editor for the 21st Century

atom-language-rust's People

Contributors

aatxe avatar alxgnon avatar atheriel avatar boereck avatar bombless avatar christianmurphy avatar colin-kiegel avatar dcampbell24 avatar flying-sheep avatar jonas-schievink avatar jonls avatar kalitaalexey avatar kevinsawicki avatar kimhyunkang avatar maccoda avatar miqh avatar palango avatar pchaigno avatar phungleson avatar portal-chan avatar pyfisch avatar severen avatar sinkuu avatar tesuji avatar theenigmablade avatar zargony avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

atom-language-rust's Issues

⏎ Enter does not fall back to previous indentation level after statement

This is explained best by example, where the pipe character | marks the cursor positions:

fn main() {
    let gt_forty_two = (0..100)
                       .filter(|&x| x > 42)
                       .collect::<Vec<_>>();| // cursor starts here, pressing [⏎ enter]
                       | // this is where it ends up
    | // this is where I expect it to end up, only one line above of course

    println!("{:?}", gt_forty_two)
}

After an expression (or unfinished statement) - so no ; at the end - the cursor aligning with the previous line is actually a good thing. Example: pressing ⏎ enter after the .filter(…) brings you to the same indentation level as the . in a new line, wonderful. But if it's a closed and finished statement, than this makes no sense.

I'm new to atom, so I don't know on which level this is handled. Is this an issue of this language package?

Indention of one line statements spilled on several lines

What I mean is that when we have a very long one liner:

try!(self.nodes.get(index).ok_or_else(|| "The index is out of bounds")).as_ref().ok_or_else(|| format!("The requested node {} is None", index))

The standard convention is to spill it on several lines, but each one should be indented one more level:

try!(self.nodes.get(index)
   .ok_or_else(|| "The index is out of bounds")).as_ref()
   .ok_or_else(|| format!("The requested node {} is None", index))

Currently it gets indented as:

try!(self.nodes.get(index)
.ok_or_else(|| "The index is out of bounds")).as_ref()
.ok_or_else(|| format!("The requested node {} is None", index))

Rust's `impl` are not highlighted quite correctly.

I noticed this earlier today, but my regex skills are not up to solving it on my own:

screen shot 2014-07-24 at 9 28 09 pm

For the first impl, the type should be identified (as it is when following struct). For the second, both type (MyObject) and trait (Clone) should be identified, and "for" should not be confused as the control structure keyword for.

Package.loadSettings is deprecated.

Store package settings files in the settings/ directory instead of scoped-properties/

Package.loadSettings (/Applications/Atom.app/Contents/Resources/app.asar/src/package.js:584:9)
<unknown> (/Applications/Atom.app/Contents/Resources/app.asar/src/package.js:186:43)
Package.measure (/Applications/Atom.app/Contents/Resources/app.asar/src/package.js:165:15)
Package.load (/Applications/Atom.app/Contents/Resources/app.asar/src/package.js:179:12)
PackageManager.loadPackage (/Applications/Atom.app/Contents/Resources/app.asar/src/package-manager.js:372:14)
PackageManager.loadPackages (/Applications/Atom.app/Contents/Resources/app.asar/src/package-manager.js:336:14)

Edit: nvm, corrupt Atom

Ligature "=>" isn't displayed correctly

I found interesting font Fira Code with ligatures, but I found that ligature for operator "=>" is not displayed correctly. So, I tried to fix this. I was getting correct ligature if I changed 'match' for operators section form this:

# Operators
{
  'comment': 'Operator'
  'name': 'keyword.operator.rust'
  'match': '(\\+|-|/|\\*|=|<=|>=|\\^|&|\\||!|%|::|\\bas\\b|<<|>>|>|<)'
}

to this (added |=>| ):

# Operators (Good)
{
  'comment': 'Operator'
  'name': 'keyword.operator.rust'
  'match': '(\\+|-|/|\\*|=>|=|<=|>=|\\^|&|\\||!|%|::|\\bas\\b|<<|>>|>|<)'
}
Correct Incorrect
Correct Incorrect

So, is my fix correct?
(Sorry for my poor English)

=> is highlighted as two separate .operator tokens

While this looks fine on most fonts, this breaks fonts like FiraCode that use ligatures.

Example of incorrect display:

Correct display (manually merged through the inspector):

This issue is also present with == and != -- they're emitted as separate .operator spans and thus the ligature is prevented.

FWIW, -> is not treated as a token and is emitted as text, which causes it to display correctly.

syntax highlighting of nested Generics

let mut board: Vec<Vec> = Vec::new();
the second Vec won't be highlighted.

I tested this with different types and it seems that it only affects the std_types
Box|Option|Path|PathBuf|Result|String|Vec

Ligatures not displaying properly

example

When using fonts that support ligatures, the rust grammar breaks them as seen in the figure above. The ligature appear correctly only in the comment section. If i select Plain Text, the ligatures appear correctly in both cases.

This is an issue in other languages also (for example ruby), you can check the discussion in
tonsky/FiraCode#63
and the solution
atom/language-ruby#117

It should have an easy fix, by adding something like the following before the operators match
{
'match': '->|=>'
'name': 'keyword.operator.rust'
}

Not sure though if this is the best way to address the issue

Structs inside other structs not highlighted properly

It seems that known types, (structs) are not being highlighted when used as a type in another struct:

struct_types

In this example, I would expect the String of BString, Vec<Bencode> of BList and BTreeMap<BString, Bencode> of BDict to be highlighted, since they are all known types.

In the Bencode struct, BInt, BString, BList and BDict are also all known types and I would expect them to be highlighted but they're not.

Adding more types to parser

It would be nice if types provided in the std crate were all able to be highlighted, such as Arc, Mutex, Rc, Sender, Receiver, etc...

It's especially helpful when declaring and passing variables that are something like, Arc<Mutex<Vec<String>>>

I'd be happy to submit a pull request with the stuff in there, but I didn't know if there was a reason, other than there are a vast number of them, that they were not included and wanted to check if such a pull request would be welcomed before doing it...

Highlighting breaks on `<` after struct declaration

When a file has a struct declaration, followed by a function with the < operator in the body, syntax highlighting breaks. Here's the simplest example I could come up with:

Broken highlighting :(

And here's the raw program text:

struct Foo { x: i32 }

fn greater_than_five(n: i32) -> bool {
    5 < n
}

// Highlighting is now broken :(
fn main() {
    let foo = Foo { x: 6 };
    let n : i32 = foo.x;
    println!("is {} > 5? {}", n, greater_than_five(n));
}

Also, a few things I noticed:

  • Putting a semicolon anywhere between the struct declaration and the < operator fixes the problem
  • It only happens with non-tuple structs with at least one field
  • Even when highlighting is broken, primitive types (u32, isize, etc) are still highlighted properly
  • Putting a > later on kind of breaks everything even more (as seen above with the runaway string)

Braces don't always lower indentation level

For example, in match statements where a comma follows, or in a closure where a paren-semicolon follows. Neither of those have correct indentation, as they both report one level more than they should. Moving the following characters onto their own line corrects the issue.

While typing it will work fine most of the time, but when pasting code with "Auto Indent on Paste" set to true it causes quite a few incorrect indents.

Below is an example of what happens: (Note the last brace ends the function, not the match statement.)

screen shot 2015-01-08 at 10 35 15 pm

Edit: Hmm, it's a bit more complicated than that, it seems that sometimes (like in let bindings) it works fine, even if the ending brace has a semicolon after it. And sometimes it works fine in if statements, and other times it doesn't. The source I'm using to test is https://github.com/gfx-rs/gfx-rs/tree/master/examples/deferred

Auto continue documentation comments

Right now regular multiline comments are continued just fine and when you hit return it will add the double forward slashes. Documentation comments, however, which use the tripple forward slashes are not continued. Rather it enters two forward slashes.

screenshot_2016-06-15_21-09-30

Turbofish syntax breaking method/function highlighting.

Edit: ::<> syntax is known has turbofish apparently.

Syntax example:

/* simplest example
    // correct
    func(); 
    // not correct
    func::<u8>();
*/

// working example
let result = "hello, world"
    // correctly highlighted
    .split(", ") 
    // not correctly highlighted
    .collect::<Vec<_>>(); 

Explanation of problem: All functions and methods are highlighted a the same color (blue here), but adding :: (or anything else) before () will change the color back to default variable color (white).

highlight formatting syntax in the macro families `format`, `write`, `print`, …

syntax and macros are explained here.

format!      // described above
write!       // first argument is a &mut io::Write, the destination
writeln!     // same as write but appends a newline
print!       // the format string is printed to the standard output
println!     // same as print but appends a newline
format_args! // described below.

we could match all macro calls starting with format…, write…, and print…, so people can define their own, and maybe also the stuff from the log crate, i.e. log!, error!, warn!, debug!, info!, trace!

Uncaught InvalidCharacterError: Failed to execute 'add' on 'DOMTokenList': The token provided ('i...

Steps Taken

  1. Installed racer and tokamak-terminal packages using native package manager
  2. Install tokamak thorugh the package manager
  3. The error appears during the installation

Atom Version: 1.8.0
System: Microsoft Windows 7 Enterprise
Thrown From: language-rust package, v0.4.6

Stack Trace

Uncaught InvalidCharacterError: Failed to execute 'add' on 'DOMTokenList': The token provided ('icon-ion ion-hammer') contains HTML space characters, which are not valid in tokens.

At /C:/Users/Thomas/.atom/packages/tool-bar/lib/tool-bar-button-view.js:45

Error: Failed to execute 'add' on 'DOMTokenList': The token provided ('icon-ion ion-hammer') contains HTML space characters, which are not valid in tokens.
    at Error (native)
    at new ToolBarButtonView (C:/Users/Thomas/.atom/packages/tool-bar/lib/tool-bar-button-view.js:36:31)
    at ToolBarManager.addButton (C:/Users/Thomas/.atom/packages/tool-bar/lib/tool-bar-manager.js:14:20)
    at Object.module.exports.Tokamak.consumeToolBar (file:///C:/Users/Thomas/.atom/packages/tokamak/lib/tokamak.coffee:124:14)
    at Provider.module.exports.Provider.provide (C:\Users\Thomas\AppData\Local\atom\app-1.8.0\resources\app.asar\node_modules\service-hub\lib\provider.js:30:52)
    at C:\Users\Thomas\AppData\Local\atom\app-1.8.0\resources\app.asar\node_modules\service-hub\lib\service-hub.js:55:26
    at doNTCallback0 (node.js:443:9)
    at process._tickCallback (node.js:372:13)

Commands

     -0:59.2.0 settings-view:open (atom-text-editor.editor.is-focused)
     -0:53.1.0 core:confirm (atom-text-editor.editor.mini.is-focused)
     -0:46.6.0 core:backspace (atom-text-editor.editor.mini.is-focused)
  2x -0:46.1.0 core:confirm (atom-text-editor.editor.mini.is-focused)
  5x -0:28.6.0 core:backspace (atom-text-editor.editor.mini.is-focused)
     -0:24.8.0 core:confirm (atom-text-editor.editor.mini.is-focused)

Config

{
  "core": {
    "disabledPackages": [
      "atom-python-run",
      "git-control"
    ]
  }
}

Installed Packages

# User
language-rust, v0.4.6
linter, v1.11.14
linter-rust, v0.4.6
tokamak, v0.2.7
tool-bar, v1.0.0

# Dev
No dev packages

Package.getStylesheetsPath is deprecated.

Store package style sheets in the styles/ directory instead of stylesheets/ in the language-rust package

Package.getStylesheetsPath (/Applications/Atom.app/Contents/Resources/app/src/package.js:448:9)
Package.getStylesheetPaths (/Applications/Atom.app/Contents/Resources/app/src/package.js:459:32)

`where` clause, not highlighting correctly.

This is where the syntax should be highlighting where but doesn't ( based on this: https://github.com/rust-lang/rfcs/blob/master/text/0135-where.md definition ). (in short they can appear besides impl, fn, trait, struct.)

impl Foo<A,B>
    where ...
{ }

impl Foo<A,B> for C
    where ...
{ }

impl Foo<A,B> for C
{
    fn foo<A,B> -> C
        where ...
    { }
}

fn foo<A,B> -> C
    where ...
{ }

struct Foo<A,B>
    where ...
{ }

trait Foo<A,B> : C
    where ...
{ }

Ironically, currently where seems to highlight everywhere but in the only cases where it should be used.

Package.getStylesheetsPath is deprecated.

Store package style sheets in the styles/ directory instead of stylesheets/ in the language-rust package Package.getStylesheetsPath c: Users Roland AppData Local atom app-0.189.0 resources app src package.js:448:9 Package.getStylesheetPaths c: Users Roland AppData Local atom app-0.189.0 resources app src package.js:459:32

Distinguish doc comments from code comments

Would anyone be interested in this if its possible? Doc comments begin with /// and are generally much longer.

I'm partial towards making doc comments lighter and collapsible. Although collapsible may be difficult as they are single-line comments.

Deprecated usage of 'editor' class

(from Deprecation Cop)
stylesheets\rust.less
Use the atom-text-editor tag instead of the editor class.
Style elements within text editors using the atom-text-editor::shadow selector or the .atom-text-editor.less file extension. If you want to target overlay elements, target them directly or as descendants of atom-overlay elements.

Channel tuples not highlighted correctly

When creating a channel:

let (tx, rx): (Sender<Vec<u8>>, Receiver<Vec<u8>>) = channel();

The brackets are not highlighted the same. Sender's are blank while the Receiver's get highlighted.

screen shot 2015-08-27 at 10 30 44 am

Automated Grammar Specs

test.rb was just a quick hack to check syntax highlighting. We should create real grammar specs like Atom's built-in language-* packages (e.g. in language-ruby)

Include fn skeleton of traits in impl

Would it be possible to enhance impl so that it includes the fn's from the trait your implementing? For instance consider this:

pub trait FooPrimitive {
    fn read<R: Read>(cursor: &mut R) -> Self;
    fn write(&self) -> Vec<u8>;
}
impl FooPrimitive for String{
    fn read<R: Read>(cursor: &mut R) -> Self{

    }
    fn write(&self) -> Vec<u8>{

    }
}

Now if i type impl and fill in FooPrimitive it would be nice if it copied these fn's automatically for me so I don't have to keep copy pasting them. :)

spawn cargo ENOENT

Whenever I save a file, I get this error pop up. I assume that the package is unable to find my installed cargo at /usr/local/bin/cargo for whatever reason. I can't see any settings in the package for setting a PATH, so I don't know where it's looking.

Add '_' character to 'Non Word Characters' list

I often want to select a part of a variable name. Consider the variable name "line_index" with the cursor right before the 'l' ([cursor]line_index). In order to select "line", I currently need to move to the end of "line" (either by hitting the "right arrow" key four times or clicking it with the mouse shudders) and hit control+shift+left to select to the beginning of the word. Adding '_' to the 'Non Word Characters' list in the package settings allows me to select "line" by hitting ctrl+shift+right. This emulates Sublime Text's alt+shift+right behavior.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.