Skip to content

Commit

Permalink
hopefully solves #15, #16 and #17
Browse files Browse the repository at this point in the history
  • Loading branch information
DamnWidget committed Jul 17, 2016
1 parent 3e17c06 commit 0b13178
Show file tree
Hide file tree
Showing 13 changed files with 52 additions and 52 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ is:
1. [Anaconda](https://github.com/DamnWidget/anaconda) plugin for Sublime Text 3
2. Rust compiler ([rustc](https://www.rust-lang.org/)) and cargo
3. [Racer](https://github.com/phildawes/racer) code completion
4. [rustfmt](https://github.com/rust-lang-nursery/rustfmt) code formatter
4. [rustfmt](https://github.com/rust-lang-nursery/rustfmt) >= 0.5.0 code formatter
5. Rust standard lib sources

## Installation
Expand Down Expand Up @@ -94,6 +94,8 @@ cargo install rustfmt

The command above will download compile and install `rustfmt` in your system, again, cargo is great.

*Note*: install `rustfmt` 0.5.0 or better for a smoothly integration, older versions give problems when used in anaconda_rust

### Install AnacondaRUST

To install AnacondaRUST you just need to follow the steps below:
Expand Down
2 changes: 1 addition & 1 deletion anaconda_lib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import os
import subprocess

from .helpers import get_settings, active_view
from anaconda_rust.anaconda_lib.helpers import get_settings, active_view

RACER_VERSION = None

Expand Down
6 changes: 4 additions & 2 deletions anaconda_lib/sublime.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@

from functools import partial

from .helpers import get_settings, active_view
from .anaconda_plugin import anaconda_sublime, Worker, Callback
from anaconda_rust.anaconda_lib.helpers import get_settings, active_view
from anaconda_rust.anaconda_lib.anaconda_plugin import (
anaconda_sublime, Worker, Callback
)


def run_linter(view=None):
Expand Down
10 changes: 5 additions & 5 deletions anaconda_rust.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
"""AnacondaRUST is a Rust IDE plugin for Sublime Text 3
"""

from .plugin_version import anaconda_required_version
from anaconda_rust.plugin_version import anaconda_required_version

from .anaconda_lib import check_racer_version
from .anaconda_lib.anaconda_plugin import anaconda_version
from anaconda_rust.anaconda_lib import check_racer_version
from anaconda_rust.anaconda_lib.anaconda_plugin import anaconda_version

if anaconda_required_version > anaconda_version:
raise RuntimeError(
Expand All @@ -19,8 +19,8 @@
)
)

from .commands import *
from .listeners import *
from anaconda_rust.commands import *
from anaconda_rust.listeners import *


def plugin_loaded():
Expand Down
8 changes: 4 additions & 4 deletions commands/doc.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@

import sublime

from ..anaconda_lib import RACER_VERSION
from ..anaconda_lib.helpers import get_settings
from ..anaconda_lib.anaconda_plugin import is_code, doc
from ..anaconda_lib.anaconda_plugin import Worker, Callback
from anaconda_rust.anaconda_lib import RACER_VERSION
from anaconda_rust.anaconda_lib.helpers import get_settings
from anaconda_rust.anaconda_lib.anaconda_plugin import is_code, doc
from anaconda_rust.anaconda_lib.anaconda_plugin import Worker, Callback


class RustDoc(doc.AnacondaDoc):
Expand Down
8 changes: 4 additions & 4 deletions commands/goto_definition.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
import sublime
import sublime_plugin

from ..anaconda_lib.helpers import get_settings
from ..anaconda_lib.anaconda_plugin import is_code
from ..anaconda_lib.anaconda_plugin import JediUsages
from ..anaconda_lib.anaconda_plugin import Worker, Callback
from anaconda_rust.anaconda_lib.helpers import get_settings
from anaconda_rust.anaconda_lib.anaconda_plugin import is_code
from anaconda_rust.anaconda_lib.anaconda_plugin import JediUsages
from anaconda_rust.anaconda_lib.anaconda_plugin import Worker, Callback


class RustGoto(sublime_plugin.TextCommand):
Expand Down
10 changes: 5 additions & 5 deletions commands/rustfmt.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@
import sublime
import sublime_plugin

from ..anaconda_lib.anaconda_plugin import is_code
from ..anaconda_lib.anaconda_plugin import ProgressBar
from ..anaconda_lib.anaconda_plugin import Worker, Callback
from ..anaconda_lib.helpers import get_settings, get_window_view
from ..anaconda_lib.helpers import file_directory
from anaconda_rust.anaconda_lib.anaconda_plugin import is_code
from anaconda_rust.anaconda_lib.anaconda_plugin import ProgressBar
from anaconda_rust.anaconda_lib.anaconda_plugin import Worker, Callback
from anaconda_rust.anaconda_lib.helpers import get_settings, get_window_view
from anaconda_rust.anaconda_lib.helpers import file_directory


class AnacondaRustFmt(sublime_plugin.TextCommand):
Expand Down
4 changes: 2 additions & 2 deletions listeners/autofmt.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

import sublime_plugin

from ..anaconda_lib.helpers import get_settings
from ..anaconda_lib.anaconda_plugin import is_code
from anaconda_rust.anaconda_lib.helpers import get_settings
from anaconda_rust.anaconda_lib.anaconda_plugin import is_code


class AutoRustFmtListener(sublime_plugin.EventListener):
Expand Down
8 changes: 4 additions & 4 deletions listeners/completion.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@

import sublime

from ..anaconda_lib.helpers import get_settings
from ..anaconda_lib.anaconda_plugin import Callback
from ..anaconda_lib.anaconda_plugin import anaconda_helpers
from ..anaconda_lib.anaconda_plugin import completion, Worker, is_code
from anaconda_rust.anaconda_lib.helpers import get_settings
from anaconda_rust.anaconda_lib.anaconda_plugin import Callback
from anaconda_rust.anaconda_lib.anaconda_plugin import anaconda_helpers
from anaconda_rust.anaconda_lib.anaconda_plugin import completion, Worker, is_code

ags = anaconda_helpers.get_settings

Expand Down
6 changes: 3 additions & 3 deletions listeners/linting.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
# Copyright (C) 2016 - Oscar Campos <[email protected]>
# This program is Free Software see LICENSE file for details

from ..anaconda_lib.sublime import run_linter
from ..anaconda_lib.anaconda_plugin import linting
from ..anaconda_lib.helpers import check_linting, get_settings
from anaconda_rust.anaconda_lib.sublime import run_linter
from anaconda_rust.anaconda_lib.anaconda_plugin import linting
from anaconda_rust.anaconda_lib.helpers import check_linting, get_settings


class BackgroundLinter(linting.BackgroundLinter):
Expand Down
3 changes: 2 additions & 1 deletion messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@
"0.2.2": "messages/0.2.2.txt",
"0.2.3": "messages/0.2.3.txt",
"0.2.4": "messages/0.2.4.txt",
"0.2.5": "messages/0.2.5.txt"
"0.2.5": "messages/0.2.5.txt",
"0.2.6": "messages/0.2.6.txt"
}
13 changes: 13 additions & 0 deletions messages/0.2.6.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Changes in 0.2.6
================

## Fixes
- Rustfmt integration is not as good as I would like, big changes regarding
it are gonna come in next releases with the addition of a new custom crate
that wraps rustfmt and make anaconda able to call Rust code directly from
Python, in the meanwhile I switch to write mode `Plain` and recommend
`rustfmt` 0.5.0 in the README file, this will hopefully solve:
* #15: Ignore children modules when formatting
* #16: Auto format adds one empty line in the beginning of the file
* #17: Auto-format sometimes deletes code

22 changes: 2 additions & 20 deletions plugin/handlers_rust/commands/rustfmt.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def rustfmt(self):
"""

args = shlex.split(
'{0} --write-mode=display --config-path {1} {2}'.format(
'{0} --write-mode=plain --config-path {1} {2}'.format(
self.settings.get('rustfmt_binary_path', 'rustfmt'),
self.settings.get('config_path'),
self.filename
Expand All @@ -69,8 +69,7 @@ def rustfmt(self):
output = output.decode('utf8')
err = err.decode('utf8')

# clean output
result = self._clean_output(output)
result = output

# delete temporary file
if os.path.exists(self.filename):
Expand All @@ -81,20 +80,3 @@ def rustfmt(self):
raise Exception(err)

return result

def _clean_output(self, output):
"""Clean lines added by rustfmt to the output
"""

with open(self.filename, 'r') as f:
sample = f.readline().strip()

result = ''
buf = output.splitlines()
for i in range(len(buf)):
if buf[i].strip() != sample:
continue
result = os.linesep.join(buf[i:])
break

return result

0 comments on commit 0b13178

Please sign in to comment.