Home Download Buy Blog Forum Support

Custom Completions Not Displaying

Custom Completions Not Displaying

Postby dasspunk on Fri Mar 02, 2012 4:47 pm

Hi,

I'm trying to create a simple creations file for use with Sahi (.sah) files. I've followed the instructions in the documentation and in this forum but for whatever reason, they do not display. I've created a file named sahi.sublime-completions (see condensed contents below) and put it in AppData/Roaming/Sublime Text 2/Packages/User/ . I open a .sah file and hit ctrl-space and none of the completions display... nor when I start typing their names.

What am I doing wrong?

TIA,
Brian


Code: Select all
{
    "scope": "source.sah",
    "completions":
    [
      "_alert",
      "_assertEqual",
      "_assertNotEqual",
      "_assertNotNull",
      "_assertNull",
      "_set"
    ]
}
dasspunk
 
Posts: 11
Joined: Fri Mar 02, 2012 4:38 pm

Re: Custom Completions Not Displaying

Postby agibsonsw on Fri Mar 02, 2012 6:32 pm

If I save a file with extension .sah it still says 'Plain Text' at the bottom-right corner.

Your completions show if I amend the scope to "text", but I don't know if there is a way to register .sah as a "source" file (rather than plain text). I'm guessing it requires a corresponding .tmLanguage file before it's recognised.
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
agibsonsw
 
Posts: 901
Joined: Fri Jan 27, 2012 9:11 pm

Re: Custom Completions Not Displaying

Postby dasspunk on Fri Mar 02, 2012 8:08 pm

Ahhh... interesting.

FYI, Sahi code is 99.9% javascript, and I'm associating ("open all with current extension as...") my .sah files the javascript syntax highlighting (which is what I want). So then is there a way to associate .sah files more formally with Javascript so that I could then add my completions and retain js syntax highlights? Or perhaps another way to accomplish the same?

Thanks,
Brian
dasspunk
 
Posts: 11
Joined: Fri Mar 02, 2012 4:38 pm

Re: Custom Completions Not Displaying

Postby agibsonsw on Fri Mar 02, 2012 9:10 pm

If it's treating .sah as JS then try amending the scope for your completions to:

Code: Select all
"scope": "source.js -string -comment -constant",

If you look towards the top of the 'JavaScript.tmLanguage' file you should see this:

Code: Select all
<dict>
   <key>comment</key>
   <string>JavaScript Syntax: version 2.0</string>
   <key>fileTypes</key>
   <array>
      <string>js</string>
      <string>htc</string>
      <string>jsx</string>
   </array>


I assume you could just add <string>sah</string> to this (carefully!!). In which case, you might be able to revert to 'source.sah' as your scope. Andy.
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
agibsonsw
 
Posts: 901
Joined: Fri Jan 27, 2012 9:11 pm

Re: Custom Completions Not Displaying

Postby agibsonsw on Fri Mar 02, 2012 9:22 pm

.. also, completions files can include snippets, as well as just simple word lists. So you could consider replacing "_set" with:

Code: Select all
{ "trigger": "_set", "contents": "_set(${1:variableName}, ${2:value});$0" },

so that you could Tab between, and insert, the arguments. If an argument is optional, I tend to use square brackets:

Code: Select all
{ "trigger": "_set", "contents": "_set(${1:variableName}${2:[, value]});$0" },

this way, it reminds me that it's optional, and I can either press delete, or over-type with ', my_value'. Andy.

PS I realise 'value' is not (really) optional in this case ;)
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
agibsonsw
 
Posts: 901
Joined: Fri Jan 27, 2012 9:11 pm

Re: Custom Completions Not Displaying

Postby dasspunk on Fri Mar 02, 2012 9:27 pm

Nice ideas Andy but I'm afraid it's still not working.

To clarify, ST2 is currently applying JS syntax to .sah files I open. This is great and works as expected.

I tried changing the scope to js (eg. source.js...) but no joy. I also tried adding <string>sah</string> to the javascript.tmLanguage file... also no joy. Also tried changing the scope back to source.sah after altering the language file. Still nothing.

What am I missing?

Thanks a bunch for the help. I really want this to work! While it won't spell doom for NP++, it'll net ST2 $59 :)

B
dasspunk
 
Posts: 11
Joined: Fri Mar 02, 2012 4:38 pm

Re: Custom Completions Not Displaying

Postby C0D312 on Fri Mar 02, 2012 9:47 pm

clippy.jpg
clippy.jpg (25.95 KiB) Viewed 880 times
It appears you are having trouble with scope. Would you like some help? Try pressing ctrl+alt+shift+p. This should list the current scope under the cursor in the status bar. The leftmost scope is the most specific and as you move right, it gets more general. If the scope is in fact Javascript, the rightmost scope will say source.js. Furthermore, whatever that rightmost scope is is what you want to reflect in your completions file.
C0D312
 
Posts: 1063
Joined: Sun Jul 10, 2011 3:23 am

Re: Custom Completions Not Displaying

Postby dasspunk on Fri Mar 02, 2012 9:57 pm

Scope is certainly part of it. With one of my .sah files open, ctrl+alt+shift+p displays source.js. I changed the scope of my sahi.sublime-completions file to "scope": "source.js", saved, restarted app and still nothing. My completions don't show up.

Any other ideas?
dasspunk
 
Posts: 11
Joined: Fri Mar 02, 2012 4:38 pm

Re: Custom Completions Not Displaying

Postby C0D312 on Fri Mar 02, 2012 10:10 pm

It looks like your completions file is syntactically wrong. It should be something like:
Code: Select all
{
    "scope": "source.js",
    "completions":
      [
        { "trigger": "_a", "contents": "_alert" },
        { "trigger": "_a", "contents": "_assertEqual" }

    ]
}
C0D312
 
Posts: 1063
Joined: Sun Jul 10, 2011 3:23 am

Re: Custom Completions Not Displaying

Postby agibsonsw on Fri Mar 02, 2012 10:17 pm

A trigger doesn't need to be provided for completions which are just "words".

Added: Make sure you don't have a spare comma at the end of your completions list :o

Check the Console for error messages (Ctrl ' apostrophe)

Check your settings to ensure that completions are enabled.
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
agibsonsw
 
Posts: 901
Joined: Fri Jan 27, 2012 9:11 pm

Next

Return to Technical Support

Who is online

Users browsing this forum: Google [Bot] and 16 guests