Add autocompletion for language keywords
Conflicts: lib/ace/edit_session.js
This commit is contained in:
parent
818dba5dba
commit
69e41521e6
33 changed files with 182 additions and 90 deletions
|
|
@ -243,7 +243,7 @@ var Autocomplete = function() {
|
|||
editor.on("changeSelection", this.$changeListener);
|
||||
editor.on("blur", this.$blurListener);
|
||||
|
||||
worker.attachToDocument(editor.session.getDocument(), {cursor: editor.getCursorPosition()}, true);
|
||||
worker.attachToDocument(editor.session.getDocument(), {cursor: editor.getCursorPosition(), keywords: editor.session.getMode().$keywordList}, true);
|
||||
|
||||
worker.on("complete", function(data) {
|
||||
var matches = data.data.matches;
|
||||
|
|
|
|||
|
|
@ -74,14 +74,14 @@ oop.inherits(AutocompleteWorker, Mirror);
|
|||
|
||||
var doc = this.doc.getValue();
|
||||
var pos = this.data.cursor;
|
||||
var part = SyntaxDetector.getContextSyntaxPart(this.doc, this.data.cursor, "javascript");
|
||||
var part = SyntaxDetector.getContextSyntaxPart(this.doc, this.data.cursor);
|
||||
var language = part.language;
|
||||
|
||||
var currentPos = { line: pos.row, col: pos.column };
|
||||
var currentNode = null;
|
||||
var matches = [], ast = null;
|
||||
|
||||
completer.complete(_self.doc, ast, this.data.cursor, currentNode, function(identifier, completions) {
|
||||
completer.complete(_self.doc, ast, this.data.cursor, this.data.keywords, currentNode, function(identifier, completions) {
|
||||
if (completions)
|
||||
matches = matches.concat(completions);
|
||||
removeDuplicateMatches(matches);
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
define(function(require, exports, module) {
|
||||
var completeUtil = require("./complete_util");
|
||||
var SPLIT_REGEX = /[^a-zA-Z_0-9\$]+/;
|
||||
var MAX_SCORE = 1000000;
|
||||
|
||||
var completer = module.exports;
|
||||
|
||||
|
|
@ -9,7 +10,7 @@ define(function(require, exports, module) {
|
|||
};
|
||||
|
||||
// For the current document, gives scores to identifiers not on frequency, but on distance from the current prefix
|
||||
function wordDistanceAnalyzer(doc, pos, prefix) {
|
||||
function wordDistanceAnalyzer(doc, pos, prefix, keywords) {
|
||||
var text = doc.getValue().trim();
|
||||
|
||||
// Determine cursor's word index
|
||||
|
|
@ -32,24 +33,28 @@ define(function(require, exports, module) {
|
|||
var distance = Math.max(prefixPosition, i) - Math.min(prefixPosition, i);
|
||||
// Score substracted from 100000 to force descending ordering
|
||||
if (Object.prototype.hasOwnProperty.call(identDict, ident))
|
||||
identDict[ident] = Math.max(1000000-distance, identDict[ident]);
|
||||
identDict[ident] = Math.max(MAX_SCORE-distance, identDict[ident]);
|
||||
else
|
||||
identDict[ident] = 1000000-distance;
|
||||
identDict[ident] = MAX_SCORE-distance;
|
||||
|
||||
}
|
||||
|
||||
for (var k = 0, l = keywords.length; k < l; k++) {
|
||||
identDict[keywords[k]] = MAX_SCORE;
|
||||
}
|
||||
return identDict;
|
||||
}
|
||||
|
||||
function analyze(doc, pos) {
|
||||
function analyze(doc, pos, keywords) {
|
||||
var line = doc.getLine(pos.row);
|
||||
var identifier = completeUtil.retrievePrecedingIdentifier(line, pos.column);
|
||||
|
||||
var analysisCache = wordDistanceAnalyzer(doc, pos, identifier);
|
||||
var analysisCache = wordDistanceAnalyzer(doc, pos, identifier, keywords);
|
||||
return analysisCache;
|
||||
}
|
||||
|
||||
completer.complete = function(doc, fullAst, pos, currentNode, callback) {
|
||||
var identDict = analyze(doc, pos);
|
||||
completer.complete = function(doc, fullAst, pos, keywords, currentNode, callback) {
|
||||
var identDict = analyze(doc, pos, keywords);
|
||||
var line = doc.getLine(pos.row);
|
||||
var identifier = completeUtil.retrievePrecedingIdentifier(line, pos.column);
|
||||
|
||||
|
|
|
|||
|
|
@ -39,7 +39,9 @@ var TextMode = require("./text").Mode;
|
|||
var oop = require("../lib/oop");
|
||||
|
||||
function Mode() {
|
||||
this.$tokenizer = new Tokenizer(new Rules().getRules());
|
||||
var highlighter = new Rules();
|
||||
this.$tokenizer = new Tokenizer(highlighter.getRules());
|
||||
this.$keywordList = new Rules(rules.$keywordList);
|
||||
this.foldingRules = new FoldMode();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -41,9 +41,13 @@ var CstyleBehaviour = require("./behaviour/cstyle").CstyleBehaviour;
|
|||
var CStyleFoldMode = require("./folding/cstyle").FoldMode;
|
||||
|
||||
var Mode = function() {
|
||||
this.$tokenizer = new Tokenizer(new c_cppHighlightRules().getRules());
|
||||
var highlighter = new c_cppHighlightRules();
|
||||
|
||||
this.$tokenizer = new Tokenizer(highlighter.getRules());
|
||||
this.$outdent = new MatchingBraceOutdent();
|
||||
this.$behaviour = new CstyleBehaviour();
|
||||
this.$keywordList = highlighter.$keywordList;
|
||||
|
||||
this.foldingRules = new CStyleFoldMode();
|
||||
};
|
||||
oop.inherits(Mode, TextMode);
|
||||
|
|
|
|||
|
|
@ -39,7 +39,9 @@ var MatchingParensOutdent = require("./matching_parens_outdent").MatchingParensO
|
|||
var Range = require("../range").Range;
|
||||
|
||||
var Mode = function() {
|
||||
this.$tokenizer = new Tokenizer(new ClojureHighlightRules().getRules());
|
||||
var highlighter = new ClojureHighlightRules();
|
||||
this.$tokenizer = new Tokenizer(highlighter.getRules());
|
||||
this.$keywordList = new Rules(rules.$keywordList);
|
||||
this.$outdent = new MatchingParensOutdent();
|
||||
};
|
||||
oop.inherits(Mode, TextMode);
|
||||
|
|
|
|||
|
|
@ -41,8 +41,10 @@ var WorkerClient = require("../worker/worker_client").WorkerClient;
|
|||
var oop = require("../lib/oop");
|
||||
|
||||
function Mode() {
|
||||
this.$tokenizer = new Tokenizer(new Rules().getRules());
|
||||
var highlighter = new Rules();
|
||||
this.$tokenizer = new Tokenizer(highlighter.getRules());
|
||||
this.$outdent = new Outdent();
|
||||
this.$keywordList = new Rules(rules.$keywordList);
|
||||
this.foldingRules = new FoldMode();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -10,9 +10,11 @@ var CstyleBehaviour = require("./behaviour/cstyle").CstyleBehaviour;
|
|||
var CStyleFoldMode = require("./folding/cstyle").FoldMode;
|
||||
|
||||
var Mode = function() {
|
||||
this.$tokenizer = new Tokenizer(new CSharpHighlightRules().getRules());
|
||||
var highlighter = new CSharpHighlightRules();
|
||||
this.$tokenizer = new Tokenizer(highlighter.getRules());
|
||||
this.$outdent = new MatchingBraceOutdent();
|
||||
this.$behaviour = new CstyleBehaviour();
|
||||
this.$keywordList = highlighter.$keywordList;
|
||||
this.foldingRules = new CStyleFoldMode();
|
||||
};
|
||||
oop.inherits(Mode, TextMode);
|
||||
|
|
|
|||
|
|
@ -41,9 +41,11 @@ var CssBehaviour = require("./behaviour/css").CssBehaviour;
|
|||
var CStyleFoldMode = require("./folding/cstyle").FoldMode;
|
||||
|
||||
var Mode = function() {
|
||||
this.$tokenizer = new Tokenizer(new CssHighlightRules().getRules());
|
||||
var highlighter = new CssHighlightRules();
|
||||
this.$tokenizer = new Tokenizer(highlighter.getRules());
|
||||
this.$outdent = new MatchingBraceOutdent();
|
||||
this.$behaviour = new CssBehaviour();
|
||||
this.$keywordList = highlighter.$keywordList;
|
||||
this.foldingRules = new CStyleFoldMode();
|
||||
};
|
||||
oop.inherits(Mode, TextMode);
|
||||
|
|
|
|||
|
|
@ -52,6 +52,7 @@ var Mode = function() {
|
|||
this.foldingRules = new CStyleFoldMode();
|
||||
|
||||
this.$tokenizer = new Tokenizer(highlighter.getRules());
|
||||
this.$keywordList = highlighter.$keywordList;
|
||||
};
|
||||
oop.inherits(Mode, CMode);
|
||||
|
||||
|
|
|
|||
|
|
@ -41,9 +41,12 @@ var CstyleBehaviour = require("./behaviour/cstyle").CstyleBehaviour;
|
|||
var CStyleFoldMode = require("./folding/cstyle").FoldMode;
|
||||
|
||||
var Mode = function() {
|
||||
this.$tokenizer = new Tokenizer(new glslHighlightRules().getRules());
|
||||
var highlighter = new glslHighlightRules();
|
||||
|
||||
this.$tokenizer = new Tokenizer(highlighter.getRules());
|
||||
this.$outdent = new MatchingBraceOutdent();
|
||||
this.$behaviour = new CstyleBehaviour();
|
||||
this.$keywordList = highlighter.$keywordList;
|
||||
this.foldingRules = new CStyleFoldMode();
|
||||
};
|
||||
oop.inherits(Mode, CMode);
|
||||
|
|
|
|||
|
|
@ -1,55 +1,58 @@
|
|||
define(function(require, exports, module) {
|
||||
|
||||
var oop = require("../lib/oop");
|
||||
var TextMode = require("./text").Mode;
|
||||
var Tokenizer = require("../tokenizer").Tokenizer;
|
||||
var GolangHighlightRules = require("./golang_highlight_rules").GolangHighlightRules;
|
||||
var MatchingBraceOutdent = require("./matching_brace_outdent").MatchingBraceOutdent;
|
||||
var CstyleBehaviour = require("./behaviour/cstyle").CstyleBehaviour;
|
||||
var CStyleFoldMode = require("./folding/cstyle").FoldMode;
|
||||
|
||||
var Mode = function() {
|
||||
this.$tokenizer = new Tokenizer(new GolangHighlightRules().getRules());
|
||||
this.$outdent = new MatchingBraceOutdent();
|
||||
this.foldingRules = new CStyleFoldMode();
|
||||
};
|
||||
oop.inherits(Mode, TextMode);
|
||||
|
||||
(function() {
|
||||
var oop = require("../lib/oop");
|
||||
var TextMode = require("./text").Mode;
|
||||
var Tokenizer = require("../tokenizer").Tokenizer;
|
||||
var GolangHighlightRules = require("./golang_highlight_rules").GolangHighlightRules;
|
||||
var MatchingBraceOutdent = require("./matching_brace_outdent").MatchingBraceOutdent;
|
||||
var CstyleBehaviour = require("./behaviour/cstyle").CstyleBehaviour;
|
||||
var CStyleFoldMode = require("./folding/cstyle").FoldMode;
|
||||
|
||||
var Mode = function() {
|
||||
var highlighter = new GolangHighlightRules();
|
||||
|
||||
this.$tokenizer = new Tokenizer(highlighter.getRules());
|
||||
this.$keywordList = highlighter.$keywordList;
|
||||
this.$outdent = new MatchingBraceOutdent();
|
||||
this.foldingRules = new CStyleFoldMode();
|
||||
};
|
||||
oop.inherits(Mode, TextMode);
|
||||
|
||||
(function() {
|
||||
|
||||
this.lineCommentStart = "//";
|
||||
this.blockComment = {start: "/*", end: "*/"};
|
||||
|
||||
this.getNextLineIndent = function(state, line, tab) {
|
||||
var indent = this.$getIndent(line);
|
||||
this.getNextLineIndent = function(state, line, tab) {
|
||||
var indent = this.$getIndent(line);
|
||||
|
||||
var tokenizedLine = this.$tokenizer.getLineTokens(line, state);
|
||||
var tokens = tokenizedLine.tokens;
|
||||
var endState = tokenizedLine.state;
|
||||
var tokenizedLine = this.$tokenizer.getLineTokens(line, state);
|
||||
var tokens = tokenizedLine.tokens;
|
||||
var endState = tokenizedLine.state;
|
||||
|
||||
if (tokens.length && tokens[tokens.length-1].type == "comment") {
|
||||
return indent;
|
||||
}
|
||||
|
||||
if (state == "start") {
|
||||
var match = line.match(/^.*[\{\(\[]\s*$/);
|
||||
if (match) {
|
||||
indent += tab;
|
||||
if (tokens.length && tokens[tokens.length-1].type == "comment") {
|
||||
return indent;
|
||||
}
|
||||
|
||||
if (state == "start") {
|
||||
var match = line.match(/^.*[\{\(\[]\s*$/);
|
||||
if (match) {
|
||||
indent += tab;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return indent;
|
||||
};//end getNextLineIndent
|
||||
return indent;
|
||||
};//end getNextLineIndent
|
||||
|
||||
this.checkOutdent = function(state, line, input) {
|
||||
return this.$outdent.checkOutdent(line, input);
|
||||
};
|
||||
this.checkOutdent = function(state, line, input) {
|
||||
return this.$outdent.checkOutdent(line, input);
|
||||
};
|
||||
|
||||
this.autoOutdent = function(state, doc, row) {
|
||||
this.$outdent.autoOutdent(doc, row);
|
||||
};
|
||||
this.autoOutdent = function(state, doc, row) {
|
||||
this.$outdent.autoOutdent(doc, row);
|
||||
};
|
||||
|
||||
}).call(Mode.prototype);
|
||||
}).call(Mode.prototype);
|
||||
|
||||
exports.Mode = Mode;
|
||||
exports.Mode = Mode;
|
||||
});
|
||||
|
|
|
|||
|
|
@ -8,7 +8,9 @@ var GroovyHighlightRules = require("./groovy_highlight_rules").GroovyHighlightRu
|
|||
|
||||
var Mode = function() {
|
||||
JavaScriptMode.call(this);
|
||||
this.$tokenizer = new Tokenizer(new GroovyHighlightRules().getRules());
|
||||
var highlighter = new GroovyHighlightRules();
|
||||
this.$tokenizer = new Tokenizer(highlighter.getRules());
|
||||
this.$keywordList = highlighter.$keywordList;
|
||||
};
|
||||
oop.inherits(Mode, JavaScriptMode);
|
||||
|
||||
|
|
|
|||
|
|
@ -10,9 +10,12 @@ var CstyleBehaviour = require("./behaviour/cstyle").CstyleBehaviour;
|
|||
var CStyleFoldMode = require("./folding/cstyle").FoldMode;
|
||||
|
||||
var Mode = function() {
|
||||
this.$tokenizer = new Tokenizer(new HaxeHighlightRules().getRules());
|
||||
var highlighter = new HaxeHighlightRules();
|
||||
|
||||
this.$tokenizer = new Tokenizer(highlighter.getRules());
|
||||
this.$outdent = new MatchingBraceOutdent();
|
||||
this.$behaviour = new CstyleBehaviour();
|
||||
this.$keywordList = highlighter.$keywordList;
|
||||
this.foldingRules = new CStyleFoldMode();
|
||||
};
|
||||
oop.inherits(Mode, TextMode);
|
||||
|
|
|
|||
|
|
@ -8,8 +8,10 @@ var JavaHighlightRules = require("./java_highlight_rules").JavaHighlightRules;
|
|||
|
||||
var Mode = function() {
|
||||
JavaScriptMode.call(this);
|
||||
var highlighter = new JavaHighlightRules();
|
||||
|
||||
this.$tokenizer = new Tokenizer(new JavaHighlightRules().getRules());
|
||||
this.$tokenizer = new Tokenizer(highlighter.getRules());
|
||||
this.$keywordList = highlighter.$keywordList;
|
||||
};
|
||||
oop.inherits(Mode, JavaScriptMode);
|
||||
|
||||
|
|
|
|||
|
|
@ -42,9 +42,12 @@ var CstyleBehaviour = require("./behaviour/cstyle").CstyleBehaviour;
|
|||
var CStyleFoldMode = require("./folding/cstyle").FoldMode;
|
||||
|
||||
var Mode = function() {
|
||||
this.$tokenizer = new Tokenizer(new JavaScriptHighlightRules().getRules());
|
||||
var highlighter = new JavaScriptHighlightRules();
|
||||
|
||||
this.$tokenizer = new Tokenizer(highlighter.getRules());
|
||||
this.$outdent = new MatchingBraceOutdent();
|
||||
this.$behaviour = new CstyleBehaviour();
|
||||
this.$keywordList = highlighter.$keywordList;
|
||||
this.foldingRules = new CStyleFoldMode();
|
||||
};
|
||||
oop.inherits(Mode, TextMode);
|
||||
|
|
|
|||
|
|
@ -38,7 +38,10 @@ var MatchingBraceOutdent = require("./matching_brace_outdent").MatchingBraceOutd
|
|||
var Range = require("../range").Range;
|
||||
|
||||
var Mode = function() {
|
||||
this.$tokenizer = new Tokenizer(new LiquidHighlightRules().getRules());
|
||||
var highlighter = new LiquidHighlightRules();
|
||||
|
||||
this.$tokenizer = new Tokenizer(highlighter.getRules());
|
||||
this.$keywordList = highlighter.$keywordList;
|
||||
this.$outdent = new MatchingBraceOutdent();
|
||||
};
|
||||
oop.inherits(Mode, TextMode);
|
||||
|
|
|
|||
|
|
@ -45,6 +45,7 @@ var Mode = function() {
|
|||
var highlighter = new LispHighlightRules();
|
||||
|
||||
this.$tokenizer = new Tokenizer(highlighter.getRules());
|
||||
this.$keywordList = highlighter.$keywordList;
|
||||
};
|
||||
oop.inherits(Mode, TextMode);
|
||||
|
||||
|
|
|
|||
|
|
@ -40,8 +40,11 @@ var Range = require("../range").Range;
|
|||
var WorkerClient = require("../worker/worker_client").WorkerClient;
|
||||
|
||||
var Mode = function() {
|
||||
this.$tokenizer = new Tokenizer(new LuaHighlightRules().getRules());
|
||||
var highlighter = new LuaHighlightRules();
|
||||
|
||||
this.$tokenizer = new Tokenizer(highlighter.getRules());
|
||||
this.foldingRules = new LuaFoldMode();
|
||||
this.$keywordList = highlighter.$keywordList;
|
||||
};
|
||||
oop.inherits(Mode, TextMode);
|
||||
|
||||
|
|
|
|||
|
|
@ -51,6 +51,7 @@ var Mode = function() {
|
|||
this.foldingRules = new FoldMode();
|
||||
|
||||
this.$tokenizer = new Tokenizer(highlighter.getRules());
|
||||
this.$keywordList = highlighter.$keywordList;
|
||||
};
|
||||
oop.inherits(Mode, TextMode);
|
||||
|
||||
|
|
|
|||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue