dart-sublime-bundle icon indicating copy to clipboard operation
dart-sublime-bundle copied to clipboard

Doc request: how to jump to definition

Open sethladd opened this issue 11 years ago • 8 comments

Hi,

I couldn't find out how to jump to a definition. For example, assume I have code like this:

var file = new File('tmp.txt');

And my cursor is on File.

How can I see the definition of File?

Can we add something to the wiki? Thanks!

sethladd avatar Aug 06 '14 07:08 sethladd

Standard ST keys are used:

  • F12: Navigate to declaration for symbol under caret (not working)
  • Ctrl+R Open 'GoTo Symbol In File'
  • Ctrl+Shift+R Open 'Goto Symbol In Project'

The last two functions should be working.

TODO:

  • [ ] update the wiki with this info

guillermooo avatar Aug 06 '14 22:08 guillermooo

Just for reference, it may be that the regexp capturing symbol information needs to capture the exact symbol name so that F12 will in turn locate a given symbol.

guillermooo avatar Aug 06 '14 22:08 guillermooo

Thanks! When we have the analysis service wired up, will F12 work?

Consider this code:

import 'package:path/path.dart' as path;
import 'dart:io';
import 'dart:convert' as convert;

main() {
  var result = Process.runSync('which', ['dart'],
        stdoutEncoding: convert.UTF8);
  var real = result.stdout.trim();
  var file = new File(real);
  print(file);
  var stat = file.statSync();
  print(stat);
  var isLink = stat.type == FileSystemEntityType.LINK;
  print("this should be true: $isLink");
  var realLocation = file.resolveSymbolicLinksSync();
  print(realLocation);
  var sdkDir = path.dirname(path.dirname(realLocation));
  print(sdkDir);
}

I have my cursor over realLocation from print(realLocation) but when I try Goto Symbol, Goto Definition, nothing happens. Should something happen?

sethladd avatar Aug 07 '14 06:08 sethladd

Native Symbol Navigation in ST

It's text-based, so it'll only work with whatever regexes are defined in Symbol List.tmPreferences. For example, var decls aren't defined in there, so that won't work. These regexes, in turn, need a function or class scope to work. AFAIK variables won't be listed in Goto Definition in any case, even if defined in Symbol List.tmPreferences. In short — symbol navigation in ST is extremely basic.

Symbol Navigation with Analysis Service

Apparently it's possible (I haven't gotten that far myself), so I hope it will work and we can override F12 to use the better implementation.

guillermooo avatar Aug 07 '14 06:08 guillermooo

In your example there will be no symbols in any of the lists. Try defining a class or a function with a return value. Unfortunately, some funcs' definitions are so ambiguous in Dart (they could be a class or a function call) that it isn't possible to capture them in syntax defs or symbol regexes.

guillermooo avatar Aug 07 '14 06:08 guillermooo

Thanks for the comments! Guess we'll have to wait for analysis services to get full support for code navigation. That's not necessarily a bad thing. :)

sethladd avatar Aug 07 '14 08:08 sethladd

Just commenting to say I was just trying out this package again just for this open definition feature. Great work so far on the package so far! The "apparently it is possible" comment intrigued me @guillermooo - has someone else done it in an open source project elsewhere?

paulevans avatar Apr 06 '15 21:04 paulevans

TODO

  • [ ] document F12 to jump to definition

guillermooo avatar May 08 '15 23:05 guillermooo