Skip to content

Commit c576c27

Browse files
committed
Merge pull request #2342 from ajaxorg/better-css-support
[Liskov] Better CSS / PHP / HTML support
2 parents d2c657d + 6a1d3b8 commit c576c27

File tree

22 files changed

+10434
-79
lines changed

22 files changed

+10434
-79
lines changed

Makefile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@ plugins-client/lib.ace/www/worker/worker-language.js plugins-client/lib.ace/www/
5656
$(wildcard plugins-client/ext.codecomplete/*/*) \
5757
$(wildcard plugins-client/ext.jslanguage/*) \
5858
$(wildcard plugins-client/ext.jslanguage/*/*) \
59+
$(wildcard plugins-client/ext.csslanguage/*) \
60+
$(wildcard plugins-client/ext.csslanguage/*/*) \
61+
$(wildcard plugins-client/ext.htmllanguage/*) \
62+
$(wildcard plugins-client/ext.htmllanguage/*/*) \
5963
$(wildcard plugins-client/ext.jsinfer/*) \
6064
$(wildcard plugins-client/ext.jsinfer/*/*) \
6165
$(wildcard node_modules/treehugger/lib/*) \
@@ -69,6 +73,8 @@ plugins-client/lib.ace/www/worker/worker-language.js plugins-client/lib.ace/www/
6973
ln -s `pwd`/plugins-client/ext.language /tmp/c9_worker_build/ext/language
7074
ln -s `pwd`/plugins-client/ext.codecomplete /tmp/c9_worker_build/ext/codecomplete
7175
ln -s `pwd`/plugins-client/ext.jslanguage /tmp/c9_worker_build/ext/jslanguage
76+
ln -s `pwd`/plugins-client/ext.csslanguage /tmp/c9_worker_build/ext/csslanguage
77+
ln -s `pwd`/plugins-client/ext.htmllanguage /tmp/c9_worker_build/ext/htmllanguage
7278
ln -s `pwd`/plugins-client/ext.linereport /tmp/c9_worker_build/ext/linereport
7379
ln -s `pwd`/plugins-client/ext.linereport_php /tmp/c9_worker_build/ext/linereport_php
7480
node Makefile.dryice.js worker

Makefile.dryice.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,9 @@ function worker(project) {
6969
'ext/jslanguage/jumptodef',
7070
'ext/jslanguage/debugger',
7171
'ext/jslanguage/outline',
72+
'ext/csslanguage/css_handler',
73+
'ext/htmllanguage/html_completer',
74+
'ext/codecomplete/mode_completer',
7275
'ext/linereport/linereport_base',
7376
'ext/linereport_php/linereport_php_worker',
7477
]

configs/default.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,8 @@ var config = [
133133
"ext/guidedtour/guidedtour",
134134
"ext/quickstart/quickstart",
135135
"ext/jslanguage/jslanguage",
136+
"ext/csslanguage/csslanguage",
137+
"ext/htmllanguage/htmllanguage",
136138
"ext/autotest/autotest",
137139
"ext/closeconfirmation/closeconfirmation",
138140
"ext/codetools/codetools",

plugins-client/ext.codecomplete/codecomplete.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ module.exports = ext.register("ext/codecomplete/codecomplete", {
2222
init : function() {
2323
language.registerLanguageHandler('ext/codecomplete/local_completer');
2424
language.registerLanguageHandler('ext/codecomplete/snippet_completer');
25+
language.registerLanguageHandler("ext/codecomplete/mode_completer");
2526
language.registerLanguageHandler('ext/codecomplete/open_files_local_completer');
2627
},
2728

plugins-client/ext.codecomplete/complete_util.js

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,30 @@ define(function(require, exports, module) {
22

33
var ID_REGEX = /[a-zA-Z_0-9\$]/;
44

5-
function retrievePreceedingIdentifier(text, pos) {
5+
function retrievePreceedingIdentifier(text, pos, regex) {
6+
regex = regex || ID_REGEX;
67
var buf = [];
78
for (var i = pos-1; i >= 0; i--) {
8-
if(ID_REGEX.test(text[i]))
9+
if (regex.test(text[i]))
910
buf.push(text[i]);
1011
else
1112
break;
1213
}
1314
return buf.reverse().join("");
1415
}
1516

17+
function retrieveFollowingIdentifier(text, pos, regex) {
18+
regex = regex || ID_REGEX;
19+
var buf = [];
20+
for (var i = pos; i < text.length; i++) {
21+
if (regex.test(text[i]))
22+
buf.push(text[i]);
23+
else
24+
break;
25+
}
26+
return buf;
27+
}
28+
1629
function prefixBinarySearch(items, prefix) {
1730
var startIndex = 0;
1831
var stopIndex = items.length - 1;
@@ -43,7 +56,25 @@ function findCompletions(prefix, allIdentifiers) {
4356
return matches;
4457
}
4558

59+
function fetchText(staticPrefix, path) {
60+
var xhr = new XMLHttpRequest();
61+
xhr.open('GET', staticPrefix + "/" + path, false);
62+
try {
63+
xhr.send();
64+
}
65+
// Likely we got a cross-script error (equivalent with a 404 in our cloud setup)
66+
catch(e) {
67+
return false;
68+
}
69+
if (xhr.status === 200)
70+
return xhr.responseText;
71+
else
72+
return false;
73+
}
74+
4675
exports.retrievePreceedingIdentifier = retrievePreceedingIdentifier;
76+
exports.retrieveFollowingIdentifier = retrieveFollowingIdentifier;
4777
exports.findCompletions = findCompletions;
78+
exports.fetchText = fetchText;
4879

4980
});
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
/**
2+
* Cloud9 Language Foundation
3+
*
4+
* @copyright 2011, Ajax.org B.V.
5+
* @license GPLv3 <http://www.gnu.org/licenses/gpl.txt>
6+
*/
7+
define(function(require, exports, module) {
8+
9+
var completeUtil = require("ext/codecomplete/complete_util");
10+
var baseLanguageHandler = require('ext/language/base_handler');
11+
12+
var completer = module.exports = Object.create(baseLanguageHandler);
13+
14+
var modeCache = {}; // extension -> static data
15+
var iconLanglist = ["php"];
16+
17+
completer.handlesLanguage = function(language) {
18+
return ["css", "php"].indexOf(language) !== -1;
19+
};
20+
21+
var ID_REGEXES = {
22+
"css": /[a-zA-Z_0-9-]/
23+
};
24+
25+
completer.complete = function(doc, fullAst, pos, currentNode, callback) {
26+
var language = this.language;
27+
var line = doc.getLine(pos.row);
28+
var idRegex = ID_REGEXES[language];
29+
var identifier = completeUtil.retrievePreceedingIdentifier(line, pos.column, idRegex);
30+
if(!identifier.length) // No completion after "."
31+
return callback([]);
32+
33+
var mode = modeCache[language];
34+
35+
if (mode === undefined) {
36+
var text;
37+
if (language)
38+
text = completeUtil.fetchText(this.staticPrefix, 'ext/codecomplete/modes/' + this.language + '.json');
39+
mode = text ? JSON.parse(text) : {};
40+
// Cache
41+
modeCache[language] = mode;
42+
}
43+
44+
function getIcon(type) {
45+
if (iconLanglist.indexOf(language) === -1)
46+
return null;
47+
var iconMap = {
48+
"variable": "property",
49+
"constant": "property",
50+
"function": "method"
51+
};
52+
var subs = Object.keys(iconMap);
53+
for (var i = 0; i < subs.length; i++)
54+
if (type.indexOf(subs[i]) !== -1)
55+
return iconMap[subs[i]];
56+
return null;
57+
}
58+
59+
// keywords, functions, constants, ..etc
60+
var types = Object.keys(mode);
61+
var matches = [];
62+
types.forEach(function (type) {
63+
var icon = getIcon(type);
64+
var nameAppend = "", replaceAppend = "";
65+
if (type.indexOf("function") !== -1) {
66+
nameAppend = "()";
67+
replaceAppend = "(^^)";
68+
}
69+
var deprecated = type.indexOf("deprecated") === -1 ? 0 : 1;
70+
var compls = completeUtil.findCompletions(identifier, mode[type]);
71+
matches.push.apply(matches, compls.map(function(m) {
72+
return {
73+
name : m + nameAppend,
74+
replaceText : m + replaceAppend,
75+
doc : deprecated ? ("Deprecated: <del>" + m + nameAppend + "</del>") : null,
76+
icon : icon,
77+
meta : type,
78+
idRegex : idRegex,
79+
priority : 2 - deprecated
80+
};
81+
}));
82+
});
83+
84+
callback(matches);
85+
};
86+
87+
88+
});
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"type": ["animation-fill-mode", "alignment-adjust", "alignment-baseline", "animation-delay", "animation-direction", "animation-duration", "animation-iteration-count", "animation-name", "animation-play-state", "animation-timing-function", "animation", "appearance", "azimuth", "backface-visibility", "background-attachment", "background-break", "background-clip", "background-color", "background-image", "background-origin", "background-position", "background-repeat", "background-size", "background", "baseline-shift", "binding", "bleed", "bookmark-label", "bookmark-level", "bookmark-state", "bookmark-target", "border-bottom", "border-bottom-color", "border-bottom-left-radius", "border-bottom-right-radius", "border-bottom-style", "border-bottom-width", "border-collapse", "border-color", "border-image", "border-image-outset", "border-image-repeat", "border-image-slice", "border-image-source", "border-image-width", "border-left", "border-left-color", "border-left-style", "border-left-width", "border-radius", "border-right", "border-right-color", "border-right-style", "border-right-width", "border-spacing", "border-style", "border-top", "border-top-color", "border-top-left-radius", "border-top-right-radius", "border-top-style", "border-top-width", "border-width", "border", "bottom", "box-align", "box-decoration-break", "box-direction", "box-flex-group", "box-flex", "box-lines", "box-ordinal-group", "box-orient", "box-pack", "box-shadow", "box-sizing", "break-after", "break-before", "break-inside", "caption-side", "clear", "clip", "color-profile", "color", "column-count", "column-fill", "column-gap", "column-rule", "column-rule-color", "column-rule-style", "column-rule-width", "column-span", "column-width", "columns", "content", "counter-increment", "counter-reset", "crop", "cue-after", "cue-before", "cue", "cursor", "direction", "display", "dominant-baseline", "drop-initial-after-adjust", "drop-initial-after-align", "drop-initial-before-adjust", "drop-initial-before-align", "drop-initial-size", "drop-initial-value", "elevation", "empty-cells", "fit", "fit-position", "float-offset", "float", "font-family", "font-size", "font-size-adjust", "font-stretch", "font-style", "font-variant", "font-weight", "font", "grid-columns", "grid-rows", "hanging-punctuation", "height", "hyphenate-after", "hyphenate-before", "hyphenate-character", "hyphenate-lines", "hyphenate-resource", "hyphens", "icon", "image-orientation", "image-rendering", "image-resolution", "inline-box-align", "left", "letter-spacing", "line-height", "line-stacking-ruby", "line-stacking-shift", "line-stacking-strategy", "line-stacking", "list-style-image", "list-style-position", "list-style-type", "list-style", "margin-bottom", "margin-left", "margin-right", "margin-top", "margin", "mark-after", "mark-before", "mark", "marks", "marquee-direction", "marquee-play-count", "marquee-speed", "marquee-style", "max-height", "max-width", "min-height", "min-width", "move-to", "nav-down", "nav-index", "nav-left", "nav-right", "nav-up", "opacity", "orphans", "outline-color", "outline-offset", "outline-style", "outline-width", "outline", "overflow-style", "overflow-x", "overflow-y", "overflow", "padding-bottom", "padding-left", "padding-right", "padding-top", "padding", "page-break-after", "page-break-before", "page-break-inside", "page-policy", "page", "pause-after", "pause-before", "pause", "perspective-origin", "perspective", "phonemes", "pitch-range", "pitch", "play-during", "position", "presentation-level", "punctuation-trim", "quotes", "rendering-intent", "resize", "rest-after", "rest-before", "rest", "richness", "right", "rotation-point", "rotation", "ruby-align", "ruby-overhang", "ruby-position", "ruby-span", "size", "speak-header", "speak-numeral", "speak-punctuation", "speak", "speech-rate", "stress", "string-set", "table-layout", "target-name", "target-new", "target-position", "target", "text-align-last", "text-align", "text-decoration", "text-emphasis", "text-height", "text-indent", "text-justify", "text-outline", "text-shadow", "text-transform", "text-wrap", "top", "transform-origin", "transform-style", "transform", "transition-delay", "transition-duration", "transition-property", "transition-timing-function", "transition", "unicode-bidi", "vertical-align", "visibility", "voice-balance", "voice-duration", "voice-family", "voice-pitch-range", "voice-pitch", "voice-rate", "voice-stress", "voice-volume", "volume", "white-space-collapse", "white-space", "widows", "width", "word-break", "word-spacing", "word-wrap", "z-index"],
3+
"function": ["rgb", "rgba", "url", "attr", "counter", "counters"],
4+
"constant": ["absolute", "after-edge", "after", "all-scroll", "all", "alphabetic", "always", "antialiased", "armenian", "auto", "avoid-column", "avoid-page", "avoid", "balance", "baseline", "before-edge", "before", "below", "bidi-override", "block-line-height", "block", "bold", "bolder", "border-box", "both", "bottom", "box", "break-all", "break-word", "capitalize", "caps-height", "caption", "center", "central", "char", "circle", "cjk-ideographic", "clone", "close-quote", "col-resize", "collapse", "column", "consider-shifts", "contain", "content-box", "cover", "crosshair", "cubic-bezier", "dashed", "decimal-leading-zero", "decimal", "default", "disabled", "disc", "disregard-shifts", "distribute-all-lines", "distribute-letter", "distribute-space", "distribute", "dotted", "double", "e-resize", "ease-in", "ease-in-out", "ease-out", "ease", "ellipsis", "end", "exclude-ruby", "fill", "fixed", "georgian", "glyphs", "grid-height", "groove", "hand", "hanging", "hebrew", "help", "hidden", "hiragana-iroha", "hiragana", "horizontal", "icon", "ideograph-alpha", "ideograph-numeric", "ideograph-parenthesis", "ideograph-space", "ideographic", "inactive", "include-ruby", "inherit", "initial", "inline-block", "inline-box", "inline-line-height", "inline-table", "inline", "inset", "inside", "inter-ideograph", "inter-word", "invert", "italic", "justify", "katakana-iroha", "katakana", "keep-all", "last", "left", "lighter", "line-edge", "line-through", "line", "linear", "list-item", "local", "loose", "lower-alpha", "lower-greek", "lower-latin", "lower-roman", "lowercase", "lr-tb", "ltr", "mathematical", "max-height", "max-size", "medium", "menu", "message-box", "middle", "move", "n-resize", "ne-resize", "newspaper", "no-change", "no-close-quote", "no-drop", "no-open-quote", "no-repeat", "none", "normal", "not-allowed", "nowrap", "nw-resize", "oblique", "open-quote", "outset", "outside", "overline", "padding-box", "page", "pointer", "pre-line", "pre-wrap", "pre", "preserve-3d", "progress", "relative", "repeat-x", "repeat-y", "repeat", "replaced", "reset-size", "ridge", "right", "round", "row-resize", "rtl", "s-resize", "scroll", "se-resize", "separate", "slice", "small-caps", "small-caption", "solid", "space", "square", "start", "static", "status-bar", "step-end", "step-start", "steps", "stretch", "strict", "sub", "super", "sw-resize", "table-caption", "table-cell", "table-column-group", "table-column", "table-footer-group", "table-header-group", "table-row-group", "table-row", "table", "tb-rl", "text-after-edge", "text-before-edge", "text-bottom", "text-size", "text-top", "text", "thick", "thin", "transparent", "underline", "upper-alpha", "upper-latin", "upper-roman", "uppercase", "use-script", "vertical-ideographic", "vertical-text", "visible", "w-resize", "wait", "whitespace", "z-index", "zero"],
5+
"color": ["aqua", "black", "blue", "fuchsia", "gray", "green", "lime", "maroon", "navy", "olive", "orange", "purple", "red", "silver", "teal", "white", "yellow"],
6+
"font": ["arial", "century", "comic", "courier", "garamond", "georgia", "helvetica", "impact", "lucida", "symbol", "system", "tahoma", "times", "trebuchet", "utopia", "verdana", "webdings", "sans-serif", "serif", "monospace"],
7+
"pseudo.element": ["after", "before", "first-letter", "first-line", "moz-selection", "selection"],
8+
"pseudo.class": ["active", "checked", "disabled", "empty", "enabled", "first-child", "first-of-type", "focus", "hover", "indeterminate", "invalid", "last-child", "last-of-type", "link", "not", "nth-child", "nth-last-child", "nth-last-of-type", "nth-of-type", "only-child", "only-of-type", "required", "root", "target", "valid", "visited"]
9+
}

0 commit comments

Comments
 (0)