Skip to content

Commit

Permalink
Refactor ContributionLoader to get rid of its options object
Browse files Browse the repository at this point in the history
Signed-off-by: Axel Boberg <[email protected]>
  • Loading branch information
axelboberg committed May 16, 2024
1 parent 62be610 commit d9c82e2
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 20 deletions.
22 changes: 4 additions & 18 deletions lib/plugin/ContributionLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,12 @@ const Logger = require('../Logger')
const logger = new Logger({ name: 'ContributionLoader' })

class ContributionLoader {
/**
* @typedef {{
* workspace: import('../Workspace')
* }} ContributionLoaderOpts
* @param { ContributionLoaderOpts } opts
*/
constructor (opts = {}) {
/**
* @private
* @type { ContributionLoaderOpts }
*/
this._opts = opts
}

/**
* Load contributions from
* a plugin manifest
* @param { import('./PluginManifest').PluginManifest } manifest
*/
loadFromManifest (manifest) {
loadFromManifest (manifest, api) {
logger.debug('Loading contributions from manifest for', manifest.name)

/*
Expand All @@ -35,9 +21,9 @@ class ContributionLoader {
below
*/
const contributionKinds = [
{ extract: this.getTypes, register: this._opts.workspace.api.types.registerType },
{ extract: this.getSettings, register: this._opts.workspace.api.settings.registerSetting },
{ extract: this.getShortcuts, register: this._opts.workspace.api.shortcuts.registerShortcut }
{ extract: this.getTypes, register: api.types.registerType },
{ extract: this.getSettings, register: api.settings.registerSetting },
{ extract: this.getShortcuts, register: api.shortcuts.registerShortcut }
]

for (const kind of contributionKinds) {
Expand Down
5 changes: 3 additions & 2 deletions lib/plugin/PluginLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ const assert = require('assert')

const context = require('./context')
const ContextStore = require('./ContextStore')

const ContributionLoader = require('./ContributionLoader')
const contributionLoader = new ContributionLoader()

const Logger = require('../Logger')
const logger = new Logger({ name: 'PluginLoader' })
Expand All @@ -34,7 +36,6 @@ class PluginLoader {
*/
this._opts = opts
this.contexts = new ContextStore()
this.contributionLoader = new ContributionLoader(opts)

assert(opts.paths?.length > 0, 'Missing required property paths in options object')
}
Expand Down Expand Up @@ -77,7 +78,7 @@ class PluginLoader {
}

if (manifest.contributes) {
this.contributionLoader.loadFromManifest(manifest)
contributionLoader.loadFromManifest(manifest, this._opts.workspace.api)
}

try {
Expand Down

0 comments on commit d9c82e2

Please sign in to comment.