WISH: Open File at Cursor #95

Open
cawoodm opened this Issue Dec 22, 2012 · 7 comments

Projects

None yet

3 participants

@cawoodm

Similar to F8 which takes me to the variable declaration I want to jump to the script path under the cursor.

If my cursor is inside the text 'require.js' it should navigate to that script if I press F8 (or Shift+F8 etc).

Logic:
1. Find the string I am at by searching forwards and backwards for ' or "
2. Check if the file exists
3. Open if it exists, subtle warning if it doesn't

@aeisenberg
@cawoodm

I mean in general, in any file. But you can try it inside a .html file in a <script> tag - it don't work.

I also wonder that there are 2 hotkeys for such similar behaviour (F8 and Ctrl+click).

@cawoodm

Example, 3rd party loader.
script

Example HTML Script Tag.
script2

As I say, Scripted should just look at the current string and resolve() it and open it if it exists.

@aeisenberg

I see what you are describing now. This is definitely doable. It would require calling js-depend in different ways and in different kinds of files, but not overly challenging to implement. It would be something nice for 0.4.0.

@kdvolder
scripted-editor member

Sounds easy enough, just one thing is a bit 'not so well-defined' here. How do we 'resolve' a string. What base directory do we use?

It seems for script tags in html files we should probably use the directory this html file is in as base.

For js files it may not be so easy as it can depend on how the file is loaded and how the string is used.

I'm sure we can do something that works for some cases which is better than not working at all :-)
E.g. we could do something special for html files and use the project dir for other cases, although it
may not be correct in all cases, it may way do what one wants for some cases.

@cawoodm

It should be generic and language agnostic and even work in .txt or .md files.

In 99% of the cases (in my experience) resolution is relative to the file being viewed. Indeed it should work as require('./module') works today.

  1. Identify the string at the cursor
  2. Call node's path.resolve based on the current dir of the file being viewed
  3. See if a file exists
  4. Open if it does
  5. Ignore (or msg in bottom right status bar) if it doesn't

Later it could be enhanced to support /paths/like/this and resolve them relative to the project root, a pre-defined folder or the OS root.

@cawoodm

Gimme gimme.

@aeisenberg aeisenberg was assigned Feb 13, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment