File tree Expand file tree Collapse file tree 5 files changed +121
-71
lines changed
Expand file tree Collapse file tree 5 files changed +121
-71
lines changed Load Diff This file was deleted.
Original file line number Diff line number Diff line change 1+ 'use babel' ;
2+
3+ async function goToDefinition ( providerRegistry ) {
4+ if ( ! providerRegistry ) {
5+ return ;
6+ }
7+
8+ const editor = atom . workspace . getActiveTextEditor ( ) ;
9+ const provider = providerRegistry . getProviderForEditor ( editor ) ;
10+
11+ const position = editor . getCursorBufferPosition ( ) ;
12+ const result = await provider . getDefinition ( editor , position ) ;
13+
14+ if ( ! result ) {
15+ atom . notifications . addError ( 'Sorry, no definitions found.' ) ;
16+ return ;
17+ }
18+
19+ const { definitions } = result ;
20+
21+ if ( ! definitions || definitions . length === 0 ) {
22+ atom . notifications . addError ( 'Sorry, no definitions found.' ) ;
23+ return ;
24+ }
25+
26+ const {
27+ path,
28+ position : { row, column } ,
29+ } = definitions [ 0 ] ;
30+
31+ if ( editor . getPath ( ) === path ) {
32+ const paneContainer = atom . workspace . paneContainerForItem ( editor ) ;
33+ paneContainer . activate ( ) ;
34+
35+ editor . setCursorBufferPosition ( [ row , column ] ) ;
36+ editor . scrollToBufferPosition ( [ row , column ] , { center : true } ) ;
37+ } else {
38+ await atom . workspace . open ( path , {
39+ initialLine : row ,
40+ initialColumn : column ,
41+ searchAllPanes : true ,
42+ activatePane : true ,
43+ activateItem : true ,
44+ } ) ;
45+ }
46+ }
47+
48+ export default goToDefinition ;
Original file line number Diff line number Diff line change 1+ 'use babel' ;
2+
3+ import { CompositeDisposable } from 'atom' ;
4+ import goToDefinition from './goToDefinition' ;
5+ import createProviderRegistry from './providerRegistry' ;
6+
7+ function package ( ) {
8+ const providerRegistry = createProviderRegistry ( ) ;
9+ let subscriptions ;
10+
11+ function activate ( ) {
12+ subscriptions = new CompositeDisposable ( ) ;
13+
14+ subscriptions . add (
15+ atom . commands . add ( 'atom-workspace' , {
16+ 'atom-ide-go-to-definition:go-to-definition' : ( ) =>
17+ goToDefinition ( providerRegistry ) ,
18+ } )
19+ ) ;
20+ }
21+
22+ function deactivate ( ) {
23+ subscriptions . dispose ( ) ;
24+ }
25+
26+ function consumeDefinitionsService ( provider ) {
27+ providerRegistry . addProvider ( provider ) ;
28+ }
29+
30+ return { activate, deactivate, consumeDefinitionsService } ;
31+ }
32+
33+ export default package ( ) ;
Original file line number Diff line number Diff line change 1+ 'use babel' ;
2+
3+ import { Disposable } from 'atom' ;
4+
5+ function providerRegistry ( ) {
6+ let providers = [ ] ;
7+
8+ function addProvider ( provider ) {
9+ const index = providers . findIndex ( p => provider . priority > p . priority ) ;
10+ if ( index === - 1 ) {
11+ providers . push ( provider ) ;
12+ } else {
13+ providers . splice ( index , 0 , provider ) ;
14+ }
15+
16+ return new Disposable ( ( ) => removeProvider ( provider ) ) ;
17+ }
18+
19+ function removeProvider ( provider ) {
20+ const index = providers . indexOf ( provider ) ;
21+ if ( index !== - 1 ) {
22+ providers . splice ( index , 1 ) ;
23+ }
24+ }
25+
26+ function getProviderForEditor ( editor ) {
27+ const grammar = editor . getGrammar ( ) . scopeName ;
28+
29+ return providers . find (
30+ provider =>
31+ ! provider . grammarScopes ||
32+ provider . grammarScopes . indexOf ( grammar ) !== - 1
33+ ) ;
34+ }
35+
36+ return { addProvider, getProviderForEditor } ;
37+ }
38+
39+ export default providerRegistry ;
Original file line number Diff line number Diff line change 11{
22 "name" : " atom-ide-definitions" ,
3- "main" : " ./lib/atom-ide-definitions " ,
3+ "main" : " ./lib/main " ,
44 "version" : " 0.1.3" ,
55 "description" : " A replacement for the Definitions functionality that was originally part of the Atom IDE package from Facebook." ,
66 "keywords" : [
You can’t perform that action at this time.
0 commit comments