improvements
This commit is contained in:
parent
61351bcb2f
commit
05e0e7004b
|
@ -62,8 +62,13 @@
|
||||||
// cache the config for subsequent *lintOnRange
|
// cache the config for subsequent *lintOnRange
|
||||||
config = deepCopy(linterConfig.getCurrent());
|
config = deepCopy(linterConfig.getCurrent());
|
||||||
let ranges;
|
let ranges;
|
||||||
if (!cm.stylusChanges || !cm.stylusChanges.length) {
|
if (
|
||||||
|
!cm.stylusChanges ||
|
||||||
|
!cm.stylusChanges.length ||
|
||||||
|
cm.stylusChanges.some(change => change.origin === 'setValue')
|
||||||
|
) {
|
||||||
// first run: lint everything
|
// first run: lint everything
|
||||||
|
cm.state.lint.marked = [];
|
||||||
// the temp monkeypatch in updateLintReport() is there
|
// the temp monkeypatch in updateLintReport() is there
|
||||||
// only to allow sep=false that returns a line array
|
// only to allow sep=false that returns a line array
|
||||||
ranges = [{
|
ranges = [{
|
||||||
|
@ -74,12 +79,22 @@
|
||||||
} else {
|
} else {
|
||||||
// sort by 'from' position in ascending order
|
// sort by 'from' position in ascending order
|
||||||
const changes = cm.stylusChanges.sort((a, b) => cmpPos(a.from, b.from));
|
const changes = cm.stylusChanges.sort((a, b) => cmpPos(a.from, b.from));
|
||||||
|
// extend ranges with pasted text
|
||||||
|
for (const change of changes) {
|
||||||
|
const addedLines = Math.max(0, change.text.length - 1);
|
||||||
|
const removedLines = Math.max(0, change.removed.length - 1);
|
||||||
|
const delta = addedLines - removedLines;
|
||||||
|
change.to = CodeMirror.Pos(
|
||||||
|
Math.max(0, change.to.line + delta),
|
||||||
|
Math.max(0, change.to.ch + change.text.last.length - change.removed.last.length + 1)
|
||||||
|
);
|
||||||
|
}
|
||||||
// merge pass 1
|
// merge pass 1
|
||||||
ranges = mergeRanges(changes);
|
ranges = mergeRanges(changes);
|
||||||
// extend up to previous } and down to next }
|
// extend up to previous } and down to next }
|
||||||
for (const range of ranges) {
|
for (const range of ranges) {
|
||||||
range.from = findBlockEndBefore(range.from, 2);
|
range.from = findBlockEndBefore(range.from, 2);
|
||||||
range.to = findBlockEndAfter(range.to, 2);
|
range.to = findBlockEndAfter(range.from, 4);
|
||||||
}
|
}
|
||||||
// merge pass 2 on the extended ranges
|
// merge pass 2 on the extended ranges
|
||||||
ranges = mergeRanges(ranges);
|
ranges = mergeRanges(ranges);
|
||||||
|
@ -99,18 +114,25 @@
|
||||||
const PREV_CMT_END = find('*/', pos, -1);
|
const PREV_CMT_END = find('*/', pos, -1);
|
||||||
const PREV_CMT_START = (prev => cmp(prev, pos) < 0 && prev)(find('/*', PREV_CMT_END, +1));
|
const PREV_CMT_START = (prev => cmp(prev, pos) < 0 && prev)(find('/*', PREV_CMT_END, +1));
|
||||||
const NEXT_CMT_END = PREV_CMT_START && (find('*/', PREV_CMT_START, +1) || EOF);
|
const NEXT_CMT_END = PREV_CMT_START && (find('*/', PREV_CMT_START, +1) || EOF);
|
||||||
const cursor = cm.getSearchCursor(/\/\*|\*\/|}/, pos, {caseFold: false});
|
const cursor = cm.getSearchCursor(/\/\*|\*\/|[{}]/, pos, {caseFold: false});
|
||||||
let cmtStart = PREV_CMT_START;
|
let cmtStart = PREV_CMT_START;
|
||||||
let cmtEnd = cmtStart && cmp(NEXT_CMT_END, pos) > 0 && NEXT_CMT_END;
|
let cmtEnd = cmtStart && cmp(NEXT_CMT_END, pos) > 0 && NEXT_CMT_END;
|
||||||
|
let blockStart;
|
||||||
let blockEnd;
|
let blockEnd;
|
||||||
while (cursor.findPrevious()) {
|
while (cursor.findPrevious()) {
|
||||||
switch (cursor.pos.match[0]) {
|
switch (cursor.pos.match[0]) {
|
||||||
|
case '{':
|
||||||
|
if (!cmtStart || cmp(cmtStart, cursor.pos.to) > 0) {
|
||||||
|
blockStart = cursor.pos.from;
|
||||||
|
}
|
||||||
|
break;
|
||||||
case '}':
|
case '}':
|
||||||
if (!cmtStart || cmp(cmtStart, cursor.pos.to) > 0) {
|
if (!cmtStart || cmp(cmtStart, cursor.pos.to) > 0) {
|
||||||
blockEnd = cursor.pos.to;
|
blockEnd = cursor.pos.to;
|
||||||
if (--repetitions <= 0) {
|
if (--repetitions <= 0 || !blockStart) {
|
||||||
return blockEnd;
|
return blockEnd;
|
||||||
}
|
}
|
||||||
|
blockStart = null;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case '/*':
|
case '/*':
|
||||||
|
@ -118,6 +140,9 @@
|
||||||
if (cmp(cmtEnd, blockEnd) > 0) {
|
if (cmp(cmtEnd, blockEnd) > 0) {
|
||||||
blockEnd = null;
|
blockEnd = null;
|
||||||
}
|
}
|
||||||
|
if (cmp(cmtEnd, blockStart) > 0) {
|
||||||
|
blockStart = null;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case '*/':
|
case '*/':
|
||||||
cmtEnd = cursor.pos.to;
|
cmtEnd = cursor.pos.to;
|
||||||
|
@ -133,13 +158,19 @@
|
||||||
function findBlockEndAfter(pos, repetitions = 1) {
|
function findBlockEndAfter(pos, repetitions = 1) {
|
||||||
const PREV_CMT_END = find('*/', pos, -1);
|
const PREV_CMT_END = find('*/', pos, -1);
|
||||||
const PREV_CMT_START = (prev => cmp(prev, pos) < 0 && prev)(find('/*', PREV_CMT_END, +1));
|
const PREV_CMT_START = (prev => cmp(prev, pos) < 0 && prev)(find('/*', PREV_CMT_END, +1));
|
||||||
const cursor = cm.getSearchCursor(/\/\*|\*\/|}/, pos, {caseFold: false});
|
const cursor = cm.getSearchCursor(/\/\*|\*\/|[{}]/, pos, {caseFold: false});
|
||||||
let cmtStart = PREV_CMT_START;
|
let cmtStart = PREV_CMT_START;
|
||||||
|
let depth = 0;
|
||||||
while (cursor.findNext()) {
|
while (cursor.findNext()) {
|
||||||
switch (cursor.pos.match[0]) {
|
switch (cursor.pos.match[0]) {
|
||||||
|
case '{':
|
||||||
|
if (!cmtStart) {
|
||||||
|
depth++;
|
||||||
|
}
|
||||||
|
break;
|
||||||
case '}':
|
case '}':
|
||||||
if (!cmtStart && --repetitions <= 0) {
|
if (!cmtStart && (--depth <= 0 && --repetitions <= 0)) {
|
||||||
return cursor.pos.to;
|
return depth < 0 ? cursor.pos.from : cursor.pos.to;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case '/*':
|
case '/*':
|
||||||
|
@ -212,7 +243,7 @@
|
||||||
const finalAnns = [];
|
const finalAnns = [];
|
||||||
const unique = new Set();
|
const unique = new Set();
|
||||||
const pushUnique = item => {
|
const pushUnique = item => {
|
||||||
const key = item.line + ' ' + item.ch + ' ' + item.message;
|
const key = item.from.line + ' ' + item.from.ch + ' ' + item.message;
|
||||||
if (!unique.has(key)) {
|
if (!unique.has(key)) {
|
||||||
unique.add(key);
|
unique.add(key);
|
||||||
finalAnns.push(item);
|
finalAnns.push(item);
|
||||||
|
|
|
@ -206,9 +206,9 @@ function updateLintReport(cm, delay) {
|
||||||
cm.getValue = sep => (sep === false ? _getValue.call(cm, sep) : '');
|
cm.getValue = sep => (sep === false ? _getValue.call(cm, sep) : '');
|
||||||
if (cm.performLint) {
|
if (cm.performLint) {
|
||||||
cm.performLint();
|
cm.performLint();
|
||||||
cm.getValue = _getValue;
|
|
||||||
update(cm);
|
update(cm);
|
||||||
}
|
}
|
||||||
|
cm.getValue = _getValue;
|
||||||
}, delay, cm);
|
}, delay, cm);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user