Skip to content
This repository has been archived by the owner on Jan 16, 2018. It is now read-only.

Add clojure support #95

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@

![demo](http://ww1.sinaimg.cn/large/71ef46c1ly1fdt8wgbaiqg20zi0j8hdu.gif)

* Support for `JavaScript(ES6 && JSX)`, `TypeScript`, `CoffeeScript`, `Python`, `Ruby`, `PHP`, `Hack`, `Perl`, `KRL`, `Erb`, `Haml`, `C/C++`, `Puppet`, `ASP`, `Shell`
* Support for `JavaScript(ES6 && JSX)`, `TypeScript`, `CoffeeScript`, `Python`, `Ruby`, `PHP`, `Hack`, `Perl`, `KRL`, `Erb`, `Haml`, `C/C++`, `Puppet`, `ASP`, `Shell`, `Clojure`
* Works with Mac OSX, Linux and Windows
* Goto-Definition functionality, by default on `Alt+Cmd+Enter`/`Ctrl+Alt+Enter`
* Support [hyperclick](https://atom.io/packages/hyperclick), `<cmd-click>` on a word to jump it's declaration

## Installing
Install the package ```goto-definition``` in Atom (Preferences->Install) or use Atom's package manager from a shell:
Install the package ```goto-definition``` in Atom (Preferences->Install) or use Atom's package manager from a shell:
```
$ apm install goto-definition
```
Expand Down
9 changes: 9 additions & 0 deletions lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,4 +163,13 @@ export default {
],
files: ['*.sh'],
},

Clojure: {
word: /[*+!\-_'?a-zA-Z][*+!\-_'?a-zA-Z0-9]*/,
regexes: [
/(^|\s+)\((ns|def[\-a-zA-Z]*)\s+{word}*/,
],
files: ['*.clj', '*.cljc', '*.cljx', '*.cljs'],
dependencies: ['Clojure'],
},
};
2 changes: 1 addition & 1 deletion lib/goto-definition.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export default {
return (editor.getSelectedText() || editor.getWordUnderCursor({
wordRegex,
includeNonWordCharacters: true,
})).replace(/[-/\\^$*+?.()|[\]{}]/g, '\\$&');
}));
},

getScanOptions(editor) {
Expand Down
133 changes: 133 additions & 0 deletions spec/fixtures/clojure-spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
/** @babel */

import helpers from '../spec-helpers';

function getSelectedWord() {
const { editor, mainModule } = helpers.getPackage();
return mainModule.getSelectedWord(editor, /[*+!\-_'?a-zA-Z][*+!\-_'?a-zA-Z0-9]*/);
}

describe('Clojure Goto Definition', () => {
let [editor, mainModule] = Array.from([]);

beforeEach(() => {
waitsForPromise(() => helpers.openFile('test.clj'));
runs(() => {
({ editor, mainModule } = helpers.getPackage());
helpers.nomalMode();
});
});

it('no definition', () => {
editor.setText('(hello-world)');
editor.setCursorBufferPosition([0, 2]);

expect(getSelectedWord()).toEqual('hello-world');
expect(helpers.getFileTypes()).toContain('*.clj');
expect(helpers.sendComand()).toBe(true);

waitsForPromise(() => helpers.waitsComplete());

expect(mainModule.definitionsView.items.length).toEqual(0);
});

it('find function', () => {
editor.setText(`\
(defn hello-world [] (list))
(hello-world)\
`);
editor.setCursorBufferPosition([1, 2]);

expect(getSelectedWord()).toEqual('hello-world');
expect(helpers.getFileTypes()).toContain('*.clj');
expect(helpers.sendComand()).toBe(true);

waitsForPromise(() => helpers.waitsComplete());

expect(mainModule.definitionsView.items.length).toEqual(1);
expect(mainModule.definitionsView.items[0].line).toEqual(0);
expect(mainModule.definitionsView.items[0].text).toContain('(defn hello-world [] (list))');
});

it('find ns, fn, and def without saving', () => {
editor.setText(`\
(ns hello-world)
(defn hello-world [] (list))
(def hello-world "")
(hello-world)\
`);
editor.setCursorBufferPosition([3, 2]);

expect(getSelectedWord()).toEqual('hello-world');
expect(helpers.getFileTypes()).toContain('*.clj');
expect(helpers.sendComand()).toBe(true);

waitsForPromise(() => helpers.waitsComplete());

expect(mainModule.definitionsView.items.length).toEqual(3);
expect(mainModule.definitionsView.items[0].line).toEqual(0);
expect(mainModule.definitionsView.items[0].text).toContain('(ns hello-world)');

expect(mainModule.definitionsView.items[1].line).toEqual(1);
expect(mainModule.definitionsView.items[1].text).toContain('(defn hello-world [] (list))');

expect(mainModule.definitionsView.items[2].line).toEqual(2);
expect(mainModule.definitionsView.items[2].text).toContain('(def hello-world "")');
});

it('find ns, fn, and def with saved file', () => {
editor.setText(`\
(ns hello-world)
(defn hello-world [] (list))
(def hello-world "")
(hello-world)\
`);
helpers.editorSave();
editor.setCursorBufferPosition([3, 1]);

expect(getSelectedWord()).toEqual('hello-world');
expect(helpers.getFileTypes()).toContain('*.clj');
expect(helpers.sendComand()).toBe(true);

waitsForPromise(() => helpers.waitsComplete());

expect(mainModule.definitionsView.items.length).toEqual(3);
expect(mainModule.definitionsView.items[0].line).toEqual(0);
expect(mainModule.definitionsView.items[0].text).toContain('(ns hello-world)');

expect(mainModule.definitionsView.items[1].line).toEqual(1);
expect(mainModule.definitionsView.items[1].text).toContain('(defn hello-world [] (list))');

expect(mainModule.definitionsView.items[2].line).toEqual(2);
expect(mainModule.definitionsView.items[2].text).toContain('(def hello-world "")');
});

return it('performance mode find ns, fn, and def with saved file', () => {
helpers.performanceMode();

editor.setText(`\
(ns hello-world)
(defn hello-world [] (list))
(def hello-world "")
(hello-world)\
`);
helpers.editorSave();
editor.setCursorBufferPosition([3, 1]);

expect(getSelectedWord()).toEqual('hello-world');
expect(helpers.getFileTypes()).toContain('*.clj');
expect(helpers.sendComand()).toBe(true);

waitsForPromise(() => helpers.waitsComplete());

expect(mainModule.definitionsView.items.length).toEqual(3);
expect(mainModule.definitionsView.items[0].line).toEqual(0);
expect(mainModule.definitionsView.items[0].text).toContain('(ns hello-world)');

expect(mainModule.definitionsView.items[1].line).toEqual(1);
expect(mainModule.definitionsView.items[1].text).toContain('(defn hello-world [] (list))');

expect(mainModule.definitionsView.items[2].line).toEqual(2);
expect(mainModule.definitionsView.items[2].text).toContain('(def hello-world "")');
});
});