Skip to content

Commit ce666b6

Browse files
committed
New approach to HTML completions in components
Removed `text.html.cfml` scope from within tag component functions and subclassed the default HTML completions class for completions there. This should help with #116.
1 parent 1394e9b commit ce666b6

5 files changed

+34
-13
lines changed

cfml_plugin.py

+22
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import sublime
22
import sublime_plugin
3+
from HTML.html_completions import HtmlTagCompletions
34
from .src.bootstrap import *
45
from .src.bootstrap import _plugin_loaded
56
from .src import completions, events, utils
@@ -119,3 +120,24 @@ class CfmlEditSettingsCommand(sublime_plugin.WindowCommand):
119120
def run(self, file, default):
120121
package_file = file.replace("{cfml_package_name}", utils.get_plugin_name())
121122
self.window.run_command("edit_settings", {"base_file": package_file, "default": default})
123+
124+
125+
class CustomHtmlTagCompletions(HtmlTagCompletions):
126+
'''
127+
There is no text.html scope in <cffunction> bodies, so this
128+
allows the HTML completions to still function there
129+
'''
130+
131+
def on_query_completions(self, view, prefix, locations):
132+
if not utils.get_setting("html_completions_in_tag_components"):
133+
return None
134+
135+
# Only trigger within CFML tag component functions
136+
selector = 'meta.class.body.tag.cfml meta.function.body.tag.cfml -source.cfml.script -source.sql'
137+
if not view.match_selector(locations[0], selector):
138+
return None
139+
140+
# check if we are inside a tag
141+
is_inside_tag = view.match_selector(locations[0], 'meta.tag - punctuation.definition.tag.begin')
142+
143+
return self.get_completions(view, prefix, locations, is_inside_tag)

settings/cfml_package.sublime-settings

+3
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@
2727
// e.g. myvar = new path.to.cfc();
2828
"instantiated_component_completions": true,
2929

30+
// provide HTML completions in tag component functions
31+
"html_completions_in_tag_components": true,
32+
3033
// if true, when a ">" is typed to end a tag the corresponding closing tag will be inserted after the cursor position,
3134
// except for the cfml tags listed in the "cfml_non_closing_tags" setting below
3235
"cfml_auto_insert_closing_tag": false,

src/minihtml.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ def render_span(span, styles, style_map):
9494
span_html = "<em>" + span_html + "</em>"
9595

9696
if span["style"]["bold"]:
97-
span_html = "<stron>" + span_html + "</strong>"
97+
span_html = "<strong>" + span_html + "</strong>"
9898

9999
span_html = start_span + span_html + "</span>"
100100

syntaxes/cfml.sublime-syntax

+4-6
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ contexts:
158158
- match: '>'
159159
scope: punctuation.definition.tag.end.cfml
160160
set:
161-
- meta_content_scope: meta.function.body.tag.cfml text.html.cfml
161+
- meta_content_scope: meta.function.body.tag.cfml
162162
- include: cffunction-end-pop
163163
- include: html
164164
- match: (?i:\b(?:name)\b)
@@ -443,11 +443,10 @@ contexts:
443443
- match: '>'
444444
scope: punctuation.definition.tag.end.cfml
445445
set:
446-
- clear_scopes: 1
447446
- meta_content_scope: source.cfml.script
448447
- match: (?i)(</)(cfscript)(>)
449448
captures:
450-
0: text.html.cfml meta.tag.cfml
449+
0: meta.tag.cfml
451450
1: punctuation.definition.tag.begin.cfml
452451
2: entity.name.tag.cfml
453452
3: punctuation.definition.tag.end.cfml
@@ -459,14 +458,13 @@ contexts:
459458
tags-with-script:
460459
- match: (?i)(<)(cfset|cfreturn|cfif|cfelseif)\b
461460
captures:
462-
0: text.html.cfml meta.tag.cfml
461+
0: meta.tag.cfml
463462
1: punctuation.definition.tag.begin.cfml
464463
2: entity.name.tag.cfml
465464
push:
466-
- clear_scopes: 1
467465
- meta_content_scope: meta.tag.cfml source.cfml.script
468466
- match: (/?>)
469-
scope: text.html.cfml meta.tag.cfml punctuation.definition.tag.end.cfml
467+
scope: meta.tag.cfml punctuation.definition.tag.end.cfml
470468
pop: true
471469
- match: \bvar\b
472470
scope: storage.type.cfml

syntaxes/src/cfml.sublime-syntax.yaml-macros

+4-6
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ contexts:
123123
- match: '>'
124124
scope: punctuation.definition.tag.end.cfml
125125
set:
126-
- meta_content_scope: meta.function.body.tag.cfml text.html.cfml
126+
- meta_content_scope: meta.function.body.tag.cfml
127127
- include: cffunction-end-pop
128128
- include: html
129129
- !attribute
@@ -271,11 +271,10 @@ contexts:
271271
- match: '>'
272272
scope: punctuation.definition.tag.end.cfml
273273
set:
274-
- clear_scopes: 1
275274
- meta_content_scope: source.cfml.script
276275
- match: (?i)(</)(cfscript)(>)
277276
captures:
278-
0: text.html.cfml meta.tag.cfml
277+
0: meta.tag.cfml
279278
1: punctuation.definition.tag.begin.cfml
280279
2: entity.name.tag.cfml
281280
3: punctuation.definition.tag.end.cfml
@@ -287,14 +286,13 @@ contexts:
287286
tags-with-script:
288287
- match: (?i)(<)(cfset|cfreturn|cfif|cfelseif)\b
289288
captures:
290-
0: text.html.cfml meta.tag.cfml
289+
0: meta.tag.cfml
291290
1: punctuation.definition.tag.begin.cfml
292291
2: entity.name.tag.cfml
293292
push:
294-
- clear_scopes: 1
295293
- meta_content_scope: meta.tag.cfml source.cfml.script
296294
- match: (/?>)
297-
scope: text.html.cfml meta.tag.cfml punctuation.definition.tag.end.cfml
295+
scope: meta.tag.cfml punctuation.definition.tag.end.cfml
298296
pop: true
299297
- match: \bvar\b
300298
scope: storage.type.cfml

0 commit comments

Comments
 (0)