Auto open corresponding files for AngularJS


#1

Hello
What I am looking for is a package that will let me open the file pairs in Angular.
So when I click to open the .ts file it will open the corresponding .html file, preferably in a split screen.
Is there a package already built that does this?
I am not finding the right combination of words to put into google to find what I need.
Thank you


#2

If you’ve searched the package database and found nothing, then there might not be a package like that to find. It would be pretty easy to write an init.coffee script that does that exact thing.


#3

Thank you :slight_smile:


#4

Okay, so this solution won’t just work for Angular, but will provide a one-click opener for any sibling files with the same name minus file extension.

# Open file and any files in the same directory that share its title.
{Directory} = require 'atom'

atom.contextMenu.add {
  ".tree-view": [{
    label: "Open with siblings"
    command: "custom:open-siblings"
  }]
}

atom.commands.add ".tree-view", "custom:open-siblings", (evt) ->
  name = evt.target.attributes.getNamedItem("title").value
  dirPath = evt.target.attributes.getNamedItem("data-path").value
  dirPath = dirPath.slice(0, dirPath.length - name.length - 1)
  name = name.slice(0, name.lastIndexOf('.'))

  dir = new Directory dirPath

  dir.getEntries (err, entries) ->
    paths = (e.getPath() for e in entries when e.isFile() and e.getBaseName().split('.')[0] == name)

    atom.workspace.open path for path in paths

#5

Thank you :slight_smile: