AsaAyers / code-links

MIT License
16 stars 8 forks source link

Follow links in PHP files? #2

Closed claytonrcarter closed 9 years ago

claytonrcarter commented 9 years ago

I forked this in the hopes that I could easily get it working in PHP files, which I think have a similar syntax for require as JS.

As far as I can tell, your code in javascript-processor.js is just looking for string literals that are relative paths (ie start with ./ or ../), yes? If so, then that should be able to work for require() statements in PHP as well. But I am no Atom hacker and can't figure out how to even get it parse/decorate the strings in a .php file.

Any chance you could give me a hint to get me started?

AsaAyers commented 9 years ago

Instead of forking you should be able to create a new package that simply parses PHP. If you publish your project on github I'll watch it so I can help as I end up working out the full API for this system.

  1. You'll need this in your package.json. docs
  "providedServices": {
    "code-links": {
      "description": "Provides code links for PHP files.",
      "versions": {
        "0.1.0": "providePHPLinks"
      }
    }
  },

Then in your main file you'll need to export a function named providePHPLinks() that returns an object that has:

# Example is in coffeescript because most atom projects seem to
class MyService
    # I'm guessing on the scope name here
    scopes: [ 'source.php' ]
    processEditor: (editor) ->
        # return an array of objects that have:
        {
            processor: this #this instance of your service.
            range: [
                # I can't see how these would ever span multiple lines, so I currently assume the line is always the same.
                [ line, firstColumn ]
                [ line, secondColumn ]
            ]
        }

    followLink(srcFilename, link) ->
AsaAyers commented 9 years ago

just looking for string literals that are relative paths (ie start with ./ or ../), yes?

Yes, this is exactly right. I intend to expand on it, but the project is a couple days old.

AsaAyers commented 9 years ago

I wanted to verify that it works, and I need to document it anyway, so I created a sample project:

https://github.com/AsaAyers/code-links-example

It just scans javascript files for the word foo and pretends it's always a link to foo.js

AsaAyers commented 9 years ago

Last night I wrote some documentation https://github.com/AsaAyers/code-links/blob/master/docs/service_provider.md

Let me know if the documentation isn't clear enough. If you publish a project let me know and I can add it to the list of known plugins