Skip to content

Commit

Permalink
fix: make sure version and help do not exit with non-zero code. (#883)
Browse files Browse the repository at this point in the history
* fix: reduce the cost of the word splitter

* fix: #880
  • Loading branch information
Jason3S authored Jan 23, 2021
1 parent a93baa0 commit b8e91f3
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 10 deletions.
20 changes: 12 additions & 8 deletions packages/cspell-lib/src/util/wordSplitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export function split(
): SplitResult {
const relWordToSplit = findNextWordText({ text: line.text, offset: offset - line.offset });
const lineOffset = line.offset;
const requested = new Map<number, Map<string, boolean>>();
const requested = new Map<number, boolean>();

if (!relWordToSplit.text) {
const text = rebaseTextOffset(relWordToSplit);
Expand Down Expand Up @@ -88,15 +88,19 @@ export function split(
}

function has(word: TextOffset): boolean {
let a = requested.get(word.offset);
const b = a?.get(word.text);
if (b !== undefined) return b;
if (!a) {
a = new Map<string, boolean>();
requested.set(word.offset, a);
const i = word.offset;
const j = word.text.length;
let v = i + (j << 20);
if (i < 1 << 20 && j < 1 << 11) {
const b = requested.get(v);
if (b !== undefined) return b;
} else {
v = -1;
}
const r = isValidWord(rebaseTextOffset(word));
a.set(word.text, r);
if (v >= 0) {
requested.set(v, r);
}
return r;
}

Expand Down
4 changes: 3 additions & 1 deletion packages/cspell/bin.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,7 @@ app.run(program, process.argv).catch((e) => {
if (!(e instanceof program.CommanderError) && !(e instanceof app.CheckFailed)) {
console.log(e);
}
process.exitCode = 1;
if (e instanceof app.CheckFailed) {
process.exitCode = e.exitCode;
}
});
2 changes: 1 addition & 1 deletion packages/cspell/src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ function template(s: string): TemplateStringsArray {
}

export class CheckFailed extends Error {
constructor(message: string, readonly errorCode: number) {
constructor(message: string, readonly exitCode: number = 1) {
super(message);
}
}

0 comments on commit b8e91f3

Please sign in to comment.