Search Unity

How to automate JS class-lookups in TextMate

Discussion in 'Scripting' started by lurid, Jul 24, 2006.

  1. lurid

    lurid

    Joined:
    Aug 28, 2005
    Posts:
    72
    Following are instructions for adding to the TextMate Javascript bundle so that you can assign a shortcut key in TM to bring up Unity docs in a TM browser, or select a Class or Class.function and go directly to its corresponding Unity docs. The process for C#/etc should be quite similar. Tweak the path to Unity.app if you have installed to somewhere non-standard.

    If you look at the Unity documentation folder in the Finder, it should be quite easy to modify this (if you have a favorite page to start from for "Root Unity Documentation" below, for example).

    These commands will also implicitly install a menu item in Bundles->JavaScript->

    Root Unity documentation
    - within TM, open the bundle editor (ctl-opt-cmd)
    - Using "Show All" filter, find the JavaScript hierarchy and open it
    - Highlight the hiearchy root (JavaScript) and click the +-down arrow menu in the bottom left corner
    - select "New Command"
    - name the new command something like "Unity Documentation"
    - paste the following code in the "Command(s)" text area
    Code (csharp):
    1.  
    2. UNITYDOC="/Applications/Unity/Unity.app/Contents/Documentation/Documentation/ScriptReference/index.html"
    3. if [[ -f $UNITYDOC ]]
    4.    then echo "<meta http-equiv=\"refresh\" content=\"0; tm-file://$UNITYDOC\">"
    5.    else echo "
    6.  
    7. Couldn't find Unity documentation."
    8. fi
    - set "Input" as None
    - set "Output" as "Show as HTML"
    - set your shortcut key to whatever you like (I used ctl-opt-h)
    - set the "Scope Selector" to source.js

    Docs for selected text
    - follow directions above up to creating the "New Command" and name something like "Documentation for Unity Word / Selection"
    - paste the following code in the "Command(s)" text area:
    Code (csharp):
    1. ref=${TM_SELECTED_TEXT}
    2. UNITYDOC="/Applications/Unity/Unity.app/Contents/Documentation/Documentation/ScriptReference/$ref.html"
    3.  
    4. if [[ -f "$UNITYDOC" ]]
    5.     then [[ -n "$UNITYDOC" ]]  exit_show_html "<meta http-equiv='Refresh' content='0;URL=tm-file://$UNITYDOC'>"
    6.     else echo "No Unity documentation found for: $TM_SELECTED_TEXT"
    7. fi
    - set "Input" to "Selected Text" or "Word"
    - set "Output" to "Show as Tool Tip"
    - shortcut key to what you like (I did ctl-opt-cmd)
    - set "Scope Selector" to "source.js"

    Note that this currently only works by directly looking up what you have selected. It cannot currently look up a function which is associated with an instantiated class for example. So you could look up "GameObject" or "GameObject.transform" by highlighting it, but it could not look up "myVar.transform".[/code]
     
  2. Scott-M

    Scott-M

    Joined:
    Jul 13, 2005
    Posts:
    23
    Fantastic - thanks!
     
  3. NCarter

    NCarter

    Joined:
    Sep 3, 2005
    Posts:
    686
    That's very useful! Using it with C# here, and it seems to work fine. Thanks a lot. :)
     
  4. Joe ByDesign

    Joe ByDesign

    Joined:
    Oct 13, 2005
    Posts:
    841
    This is a really nice addition to TextMate (recently picked it up for Unity, works great). Anyone with ideas on using selected text to search Unity docs?

    I've tried the follow, but it always returns the 'not found' despite working fine in my browser :

    Code (csharp):
    1.  
    2. ref=${TM_SELECTED_TEXT}
    3. UNITYDOC="/Applications/Unity/Unity.app/Contents/Documentation/Documentation/ScriptReference/30_search.html?q=$ref"
    4.  
    5. if [[ -f "$UNITYDOC" ]]
    6.    then [[ -n "$UNITYDOC" ]]  exit_show_html "<meta http-equiv='Refresh' content='0;URL=tm-file://localhost/$UNITYDOC'>"
    7.    else echo "Unity documentation not found"
    8. fi
    9.  
     
  5. zumwalt

    zumwalt

    Joined:
    Apr 18, 2007
    Posts:
    2,287
    I got it working with Javascript, how did you get it to work with C#, there is only C and C++ in the list..
     
  6. Joe ByDesign

    Joe ByDesign

    Joined:
    Oct 13, 2005
    Posts:
    841
  7. zumwalt

    zumwalt

    Joined:
    Apr 18, 2007
    Posts:
    2,287
    Thanks, I have plugged that into textmate, but don't have syntax highlighting or autocomplete, I'll play with it more later, great work guys! kudos!
     
  8. Joe ByDesign

    Joe ByDesign

    Joined:
    Oct 13, 2005
    Posts:
    841
    Neil cleared this one up; looks like we were testing for existance of the file and since we're trying use it to search, it fails.

    replace the if ... fi section with this:

    Code (csharp):
    1. exit_show_html "<meta http-equiv='Refresh' content='0;URL=file://localhost/$UNITYDOC'>"
    all thanks to Neil for this!
     
  9. Daniel_Brauer

    Daniel_Brauer

    Unity Technologies

    Joined:
    Aug 11, 2006
    Posts:
    3,355
    Does this work for anyone? I always get a blank search page when I try it.
     
  10. Joe ByDesign

    Joe ByDesign

    Joined:
    Oct 13, 2005
    Posts:
    841
    These are the 2 I use;

    Documentation (general):
    Code (csharp):
    1. UNITYDOC="/Applications/Unity/Unity.app/Contents/Documentation/Documentation/ScriptReference/index.html"
    2. if [[ -f $UNITYDOC ]]
    3.  then echo "<meta http-equiv=\"refresh\" content=\"0; tm-file://$UNITYDOC\">"
    4.  else echo "
    5.  
    6. Couldn't find Unity documentation."
    7. fi
    8.  

    Documentation (selection):
    Code (csharp):
    1.  
    2. ref=${TM_SELECTED_TEXT}
    3. UNITYDOC="/Applications/Unity/Unity.app/Contents/Documentation/Documentation/ScriptReference/30_search.html?q=$ref"
    4.  
    5. exit_show_html "<meta http-equiv='Refresh' content='0;URL=file://localhost/$UNITYDOC'>"
    6.  
     

    Attached Files:

  11. Daniel_Brauer

    Daniel_Brauer

    Unity Technologies

    Joined:
    Aug 11, 2006
    Posts:
    3,355
    Got it:
    Code (csharp):
    1. ref=${TM_SELECTED_TEXT:-$TM_CURRENT_WORD}
    2. UNITYDOC="/Applications/Unity/Unity.app/Contents/Documentation/Documentation/ScriptReference/$ref.html"
    3. UNITYSEARCH="/Applications/Unity/Unity.app/Contents/Documentation/Documentation/ScriptReference/30_search.html?q=$ref"
    4.  
    5. if [[ -f "$UNITYDOC" ]]
    6.     then [[ -n "$UNITYDOC" ]]  exit_show_html "<meta http-equiv='Refresh' content='0;URL=tm-file://$UNITYDOC'>"
    7.     else exit_show_html "<meta http-equiv='Refresh' content='0;URL=file://localhost$UNITYSEARCH'>"
    8. fi
    This script will look for an exact match with the selected text or word, and fall back to a search. Note that you don't actually need to set anything below the script field. exit_show_html always shows HTML, and ${TM_SELECTED_TEXT:-$TM_CURRENT_WORD} will always use the currently selected text or the closest word to the caret. The input/output options are for scripts that use stdin/out.
     
  12. thylaxene

    thylaxene

    Joined:
    Oct 10, 2005
    Posts:
    716
    that still doesn't work for me.

    Cheers.
     
  13. Daniel_Brauer

    Daniel_Brauer

    Unity Technologies

    Joined:
    Aug 11, 2006
    Posts:
    3,355
    In what way doesn't it work? Do you get a blank page, or a blank search page when you look up something that isn't a class?
     
  14. thylaxene

    thylaxene

    Joined:
    Oct 10, 2005
    Posts:
    716
    it works on an exact search of a class name. but the full just gives me a blank page.

    also is there a way to populate the contextual menu, so one can select text right-click and veiw documentation?

    Cheers.