Skip to content
This repository has been archived by the owner on Sep 6, 2021. It is now read-only.

Another two straightforward refactoring tasks for Language support #3301

Merged
merged 5 commits into from
Mar 31, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/editor/CSSInlineEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ define(function (require, exports, module) {
*/
function htmlToCSSProvider(hostEditor, pos) {
// Only provide a CSS editor when cursor is in HTML content
if (hostEditor.getModeForSelection() !== "html") {
if (hostEditor.getLanguageForSelection().getId() !== "html") {
return null;
}

Expand Down
2 changes: 1 addition & 1 deletion src/extensions/default/QuickOpenCSS/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ define(function (require, exports, module) {
QuickOpen.addQuickOpenPlugin(
{
name: "CSS Selectors",
fileTypes: ["css"],
languageIds: ["css"],
done: function () {},
search: search,
match: match,
Expand Down
2 changes: 1 addition & 1 deletion src/extensions/default/QuickOpenHTML/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ define(function (require, exports, module) {
QuickOpen.addQuickOpenPlugin(
{
name: "html ids",
fileTypes: ["html"],
languageIds: ["html"],
done: function () {},
search: search,
match: match,
Expand Down
2 changes: 1 addition & 1 deletion src/extensions/default/QuickOpenJavaScript/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ define(function (require, exports, module) {
QuickOpen.addQuickOpenPlugin(
{
name: "JavaScript functions",
fileTypes: ["js"],
languageIds: ["javascript"],
done: function () {},
search: search,
match: match,
Expand Down
28 changes: 18 additions & 10 deletions src/search/QuickOpen.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ define(function (require, exports, module) {
StringUtils = require("utils/StringUtils"),
Commands = require("command/Commands"),
ProjectManager = require("project/ProjectManager"),
LanguageManager = require("language/LanguageManager"),
KeyEvent = require("utils/KeyEvent"),
ModalBar = require("widgets/ModalBar").ModalBar,
StringMatch = require("utils/StringMatch");
Expand Down Expand Up @@ -97,9 +98,9 @@ define(function (require, exports, module) {
/**
* Defines API for new QuickOpen plug-ins
*/
function QuickOpenPlugin(name, fileTypes, done, search, match, itemFocus, itemSelect, resultsFormatter) {
function QuickOpenPlugin(name, languageIds, done, search, match, itemFocus, itemSelect, resultsFormatter) {
this.name = name;
this.fileTypes = fileTypes;
this.languageIds = languageIds;
this.done = done;
this.search = search;
this.match = match;
Expand All @@ -112,7 +113,7 @@ define(function (require, exports, module) {
* Creates and registers a new QuickOpenPlugin
*
* @param { name: string,
* fileTypes:Array.<string>,
* languageIds:Array.<string>,
* done: function(),
* search: function(string, !StringMatch.StringMatcher):Array.<SearchResult|string>,
* match: function(string):boolean,
Expand All @@ -124,8 +125,8 @@ define(function (require, exports, module) {
* Parameter Documentation:
*
* name - plug-in name, **must be unique**
* fileTypes - file types array. Example: ["js", "css", "txt"]. An empty array
* indicates all file types.
* languageIds - language Ids array. Example: ["javascript", "css", "html"]. An empty array
* indicates all language IDs.
* done - called when quick open is complete. Plug-in should clear its internal state.
* search - takes a query string and a StringMatcher (the use of which is optional but can speed up your searches) and returns an array of strings that match the query.
* match - takes a query string and returns true if this plug-in wants to provide
Expand All @@ -141,9 +142,17 @@ define(function (require, exports, module) {
* cancels Quick Open (via Esc), those changes are automatically reverted.
*/
function addQuickOpenPlugin(pluginDef) {
if (pluginDef.fileTypes) {
console.warn("Using fileTypes for QuickOpen plugins is deprecated. Use languageIds instead.");
pluginDef.languageIds = pluginDef.fileTypes.map(function (extension) {
return LanguageManager.getLanguageForPath("file." + extension).getId();
});
delete pluginDef.fileTypes;
}

plugins.push(new QuickOpenPlugin(
pluginDef.name,
pluginDef.fileTypes,
pluginDef.languageIds,
pluginDef.done,
pluginDef.search,
pluginDef.match,
Expand Down Expand Up @@ -529,14 +538,13 @@ define(function (require, exports, module) {
// Try to invoke a search plugin
var curDoc = DocumentManager.getCurrentDocument();
if (curDoc) {
var filename = _filenameFromPath(curDoc.file.fullPath, true);
var extension = filename.slice(filename.lastIndexOf(".") + 1, filename.length);
var languageId = curDoc.getLanguage().getId();

var i;
for (i = 0; i < plugins.length; i++) {
var plugin = plugins[i];
var extensionMatch = plugin.fileTypes.indexOf(extension) !== -1 || plugin.fileTypes.length === 0;
if (extensionMatch && plugin.match && plugin.match(query)) {
var LanguageIdMatch = plugin.languageIds.indexOf(languageId) !== -1 || plugin.languageIds.length === 0;
if (LanguageIdMatch && plugin.match && plugin.match(query)) {
currentPlugin = plugin;

// Look up the StringMatcher for this plugin.
Expand Down