Skip to content

Commit

Permalink
fix after rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
nightwing committed Apr 14, 2024
1 parent 5278fb3 commit 1a14040
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 43 deletions.
3 changes: 2 additions & 1 deletion demo/kitchen-sink/demo.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ function loadLanguageProvider(editor) {
}
}, true);
function showOccurrenceMarkers(session, positions) {
if (!session.state) session.state = {}
if (!session.state.occurrenceMarkers) {
session.state.occurrenceMarkers = new MarkerGroup(session);
}
Expand Down Expand Up @@ -179,7 +180,7 @@ function loadLanguageProvider(editor) {
let docPos = e.getDocumentPosition();

languageProvider.doHover(session, docPos, function(hover) {
var errorMarker = session.state?.diagnosticMarkers.getMarkerAtPosition(docPos);
var errorMarker = session.state?.diagnosticMarkers?.getMarkerAtPosition(docPos);

if (!errorMarker && !hover?.content) return;

Expand Down
2 changes: 1 addition & 1 deletion src/layer/text.js
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ class Text {
if (!isTextToken(token.type.toString())) {
var classes = "ace_" + token.type.toString().replace(/\./g, " ace_");
var span = this.dom.createElement("span");
if (token.type.toString() === "fold")
if (token.type.toString() === "fold") {
span.style.width = (token.value.length * this.config.characterWidth) + "px";
span.setAttribute("title", nls("inline-fold.closed.title", "Unfold code"));
}
Expand Down
63 changes: 38 additions & 25 deletions src/scope.js
Original file line number Diff line number Diff line change
@@ -1,55 +1,68 @@
"use strict";

var Scope = function (name, parent) {
this.name = name.toString();
this.children = {};
this.parent = parent;
};
(function () {
Scope.prototype.toString = function () {
class Scope {
/**
* @param {string} name
* @param {Scope} [parent]
*/
constructor(name, parent) {
this.name = name.toString();
this.children = {};
this.parent = parent;
}
toString() {
return this.name;
};
Scope.prototype.get = function (name, extraId = '') {
return this.children[name.toString() + extraId] || (this.children[name.toString() + extraId] = new Scope(
name, this));
};
Scope.prototype.find = function (states) {
}
/**
* @param {string} name
* @param {string|undefined} extraId
*/
get(name, extraId) {
var id = name.toString() + (extraId || "");
return this.children[id] || (
this.children[id] = new Scope(name, this)
);
}
find(states) {
var s = this;
while (s && !states[s.name]) {
s = s.parent;
}
return states[s ? s.name : "start"];
};
Scope.prototype.replace = function (a, b) {
}
replace(a, b) {
return this.name.replace(a, b);
};
Scope.prototype.indexOf = function (a, b) {
}
indexOf(a, b) {
return this.name.indexOf(a, b);
};
Scope.prototype.hasParent = function (states) {
}
/**
* @param {string} states
*/
hasParent(states) {
var s = this;
while (s && states !== s.name) {
s = s.parent;
}
return s ? 1 : -1;
};
Scope.prototype.count = function () {
}
count() {
var s = 1;
for (var i in this.children) s += this.children[i].count();
return s;
};
}
/**
*
* @returns {string[]}
*/
Scope.prototype.getAllScopeNames = function () {
getAllScopeNames() {
var scopeNames = [];
var self = this;
do {
scopeNames.push(self.name);
} while (self = self.parent);
return scopeNames;
};
}).call(Scope.prototype);
}
}

exports.Scope = Scope;
31 changes: 15 additions & 16 deletions src/tokenizer.js
Original file line number Diff line number Diff line change
Expand Up @@ -372,21 +372,19 @@ Tokenizer.prototype.reportError = reportError;
*
* @constructor
**/
var CustomTokenizer = function(rules, modeName) {
Tokenizer.call(this, rules);
this.rootScope = new Scope(modeName);
}
oop.inherits(CustomTokenizer, Tokenizer);

(function() {
class CustomTokenizer extends Tokenizer {
constructor(rules, modeName) {
super(rules);
this.rootScope = new Scope(modeName);
}
/**
* Returns an object containing two properties: `tokens`, which contains all the tokens; and `state`, the current state.
* @param {String} line
* @param {String|Scope} startState
* @returns {Object}
* @override
**/
this.getLineTokens = function(line, startState) {
getLineTokens(line, startState) {
var stack = [];

var currentState = (startState !== undefined) ? (startState instanceof Scope) ? startState
Expand All @@ -404,7 +402,7 @@ oop.inherits(CustomTokenizer, Tokenizer);
var lastIndex = 0;
var matchAttempts = 0;

var token = {type: null, value: ""};
var token = { type: null, value: "" };

while (match = re.exec(line)) {
var type = currentState.get(mapping.defaultToken);
Expand All @@ -420,11 +418,11 @@ oop.inherits(CustomTokenizer, Tokenizer);
} else {
if (token.type)
tokens.push(token);
token = {type: currentState.get(type), value: skipped};
token = { type: currentState.get(type), value: skipped };
}
}

for (var i = 0; i < match.length-2; i++) {
for (var i = 0; i < match.length - 2; i++) {
if (match[i + 1] === undefined)
continue;

Expand Down Expand Up @@ -491,14 +489,14 @@ oop.inherits(CustomTokenizer, Tokenizer);
} else {
if (token.type)
tokens.push(token);
token = {type: currentState.get(type), value: value};
token = { type: currentState.get(type), value: value };
}
} else if (type) {
if (token.type)
tokens.push(token);
token = {type: null, value: ""};
token = { type: null, value: "" };
for (var i = 0; i < type.length; i++) {
type[i].type=currentState.get(type[i].type);
type[i].type = currentState.get(type[i].type);
tokens.push(type[i]);
}
}
Expand Down Expand Up @@ -544,8 +542,9 @@ oop.inherits(CustomTokenizer, Tokenizer);
return {
tokens: tokens
};
};
}).call(CustomTokenizer.prototype);
}
}


exports.Tokenizer = Tokenizer;
exports.CustomTokenizer = CustomTokenizer;

0 comments on commit 1a14040

Please sign in to comment.