Skip to content

Commit

Permalink
Merge pull request microsoft#37 from nicoabie/exclude-features
Browse files Browse the repository at this point in the history
Feature exclude
  • Loading branch information
alexdima authored Sep 20, 2018
2 parents d46361b + 97fa344 commit 1bd93df
Show file tree
Hide file tree
Showing 4 changed files with 713 additions and 677 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ Some languages share the same web worker. If one of the following languages is i

* `features` (`string[]`) - include only a subset of the editor features.
* default value: `['accessibilityHelp', 'bracketMatching', 'caretOperations', 'clipboard', 'codeAction', 'codelens', 'colorDetector', 'comment', 'contextmenu', 'coreCommands', 'cursorUndo', 'dnd', 'find', 'folding', 'fontZoom', 'format', 'goToDefinitionCommands', 'goToDefinitionMouse', 'gotoError', 'gotoLine', 'hover', 'inPlaceReplace', 'inspectTokens', 'iPadShowKeyboard', 'linesOperations', 'links', 'multicursor', 'parameterHints', 'quickCommand', 'quickOutline', 'referenceSearch', 'rename', 'smartSelect', 'snippets', 'suggest', 'toggleHighContrast', 'toggleTabFocusMode', 'transpose', 'wordHighlighter', 'wordOperations', 'wordPartOperations']`.
* excluded features: It is also possible to exclude certain default features prefixing them with an exclamation mark '!'.

## Contributing

Expand Down
23 changes: 22 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,31 @@ const languagesById = fromPairs(
);
const featuresById = mapValues(FEATURES, (feature, key) => mixin({ label: key }, feature))

function getFeaturesIds(userFeatures, predefinedFeaturesById) {
function notContainedIn(arr) {
return (element) => arr.indexOf(element) === -1;
}

let featuresIds;

if (userFeatures.length) {
const excludedFeatures = userFeatures.filter(f => f[0] === '!').map(f => f.slice(1));
if (excludedFeatures.length) {
featuresIds = Object.keys(predefinedFeaturesById).filter(notContainedIn(excludedFeatures))
} else {
featuresIds = userFeatures;
}
} else {
featuresIds = Object.keys(predefinedFeaturesById);
}

return featuresIds;
}

class MonacoWebpackPlugin {
constructor(options = {}) {
const languages = options.languages || Object.keys(languagesById);
const features = options.features || Object.keys(featuresById);
const features = getFeaturesIds(options.features || [], featuresById);
const output = options.output || '';
this.options = {
languages: languages.map((id) => languagesById[id]).filter(Boolean),
Expand Down
Loading

0 comments on commit 1bd93df

Please sign in to comment.