You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
123 lines
4.7 KiB
123 lines
4.7 KiB
"use strict"; |
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { |
|
if (k2 === undefined) k2 = k; |
|
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); |
|
}) : (function(o, m, k, k2) { |
|
if (k2 === undefined) k2 = k; |
|
o[k2] = m[k]; |
|
})); |
|
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { |
|
Object.defineProperty(o, "default", { enumerable: true, value: v }); |
|
}) : function(o, v) { |
|
o["default"] = v; |
|
}); |
|
var __importStar = (this && this.__importStar) || function (mod) { |
|
if (mod && mod.__esModule) return mod; |
|
var result = {}; |
|
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); |
|
__setModuleDefault(result, mod); |
|
return result; |
|
}; |
|
Object.defineProperty(exports, "__esModule", { value: true }); |
|
exports.internal = exports.getIgnoreRegExpFromDocument = exports.getIgnoreWordsFromDocument = exports.getInDocumentSettings = void 0; |
|
const gensequence_1 = require("gensequence"); |
|
const Text = __importStar(require("../util/text")); |
|
const CSpellSettingsServer_1 = require("./CSpellSettingsServer"); |
|
// cspell:ignore gimuy |
|
const regExMatchRegEx = /\/.*\/[gimuy]*/; |
|
const regExInFileSettings = [/(?:spell-?checker|cSpell)::?\s*(.*)/gi, /(LocalWords:?\s+.*)/g]; |
|
function getInDocumentSettings(text) { |
|
const settings = getPossibleInDocSettings(text) |
|
.concatMap((a) => parseSettingMatch(a)) |
|
.reduce((s, setting) => { |
|
return CSpellSettingsServer_1.mergeInDocSettings(s, setting); |
|
}, { id: 'in-doc-settings' }); |
|
return settings; |
|
} |
|
exports.getInDocumentSettings = getInDocumentSettings; |
|
function parseSettingMatch(matchArray) { |
|
const [, possibleSetting = ''] = matchArray; |
|
const settingParsers = [ |
|
[/^(?:enable|disable)(?:allow)?CompoundWords/i, parseCompoundWords], |
|
[/^words?\s/i, parseWords], |
|
[/^ignore(?:words?)?\s/i, parseIgnoreWords], |
|
[/^ignore_?Reg_?Exp\s+.+$/i, parseIgnoreRegExp], |
|
[/^include_?Reg_?Exp\s+.+$/i, parseIncludeRegExp], |
|
[/^locale?\s/i, parseLocal], |
|
[/^language\s/i, parseLocal], |
|
[/^dictionaries\s/i, parseDictionaries], |
|
[/^LocalWords:/, parseWords], |
|
]; |
|
return settingParsers |
|
.filter(([regex]) => regex.test(possibleSetting)) |
|
.map(([, fn]) => fn) |
|
.map((fn) => fn(possibleSetting)); |
|
} |
|
function parseCompoundWords(match) { |
|
const allowCompoundWords = /enable/i.test(match); |
|
return { id: 'in-doc-allowCompoundWords', allowCompoundWords }; |
|
} |
|
function parseWords(match) { |
|
const words = match.split(/[,\s]+/g).slice(1); |
|
return { id: 'in-doc-words', words }; |
|
} |
|
function parseLocal(match) { |
|
const parts = match.trim().split(/\s+/); |
|
const language = parts.slice(1).join(' '); |
|
return language ? { id: 'in-doc-local', language } : {}; |
|
} |
|
function parseIgnoreWords(match) { |
|
const wordsSetting = parseWords(match); |
|
return { id: 'in-doc-ignore', ignoreWords: wordsSetting.words }; |
|
} |
|
function parseRegEx(match) { |
|
const patterns = [match.replace(/^[^\s]+\s+/, '')].map((a) => { |
|
const m = a.match(regExMatchRegEx); |
|
if (m && m[0]) { |
|
return m[0]; |
|
} |
|
return a.replace(/((?:[^\s]|\\ )+).*/, '$1'); |
|
}); |
|
return patterns; |
|
} |
|
function parseIgnoreRegExp(match) { |
|
const ignoreRegExpList = parseRegEx(match); |
|
return { id: 'in-doc-ignoreRegExp', ignoreRegExpList }; |
|
} |
|
function parseIncludeRegExp(match) { |
|
const includeRegExpList = parseRegEx(match); |
|
return { id: 'in-doc-includeRegExp', includeRegExpList }; |
|
} |
|
function parseDictionaries(match) { |
|
const dictionaries = match.split(/[,\s]+/g).slice(1); |
|
return { id: 'in-doc-dictionaries', dictionaries }; |
|
} |
|
function getPossibleInDocSettings(text) { |
|
return gensequence_1.genSequence(regExInFileSettings).concatMap((regexp) => Text.match(regexp, text)); |
|
} |
|
function getWordsFromDocument(text) { |
|
const { words = [] } = getInDocumentSettings(text); |
|
return words; |
|
} |
|
function getIgnoreWordsFromDocument(text) { |
|
const { ignoreWords = [] } = getInDocumentSettings(text); |
|
return ignoreWords; |
|
} |
|
exports.getIgnoreWordsFromDocument = getIgnoreWordsFromDocument; |
|
function getIgnoreRegExpFromDocument(text) { |
|
const { ignoreRegExpList = [] } = getInDocumentSettings(text); |
|
return ignoreRegExpList; |
|
} |
|
exports.getIgnoreRegExpFromDocument = getIgnoreRegExpFromDocument; |
|
/** |
|
* These internal functions are used exposed for unit testing. |
|
*/ |
|
exports.internal = { |
|
getPossibleInDocSettings, |
|
getWordsFromDocument, |
|
parseWords, |
|
parseCompoundWords, |
|
parseIgnoreRegExp, |
|
parseIgnoreWords, |
|
}; |
|
//# sourceMappingURL=InDocSettings.js.map
|