Skip to content

Commit

Permalink
fix: make getOriginatorPackageName a free function
Browse files Browse the repository at this point in the history
  • Loading branch information
aminya committed Dec 31, 2020
1 parent 115ae4f commit 3d67d03
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions lib/mixins/decoration-management.js
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ export default class DecorationManagement {
const { type, plugin } = decorationParams

if (plugin == null) {
decorationParams.plugin = this.getOriginatorPackageName()
decorationParams.plugin = getOriginatorPackageName()
}

if (decorationParams.scope == null && decorationParams.class != null) {
Expand Down Expand Up @@ -422,16 +422,6 @@ export default class DecorationManagement {
return decoration
}

getOriginatorPackageName () {
const line = new Error().stack.split('\n')[3]
const filePath = line.split('(')[1].replace(')', '')
const re = new RegExp(
atom.packages.getPackageDirPaths().join('|') + escapeRegExp(path.sep)
)
const plugin = filePath.replace(re, '').split(path.sep)[0].replace(/minimap-|-minimap/, '')
return plugin.indexOf(path.sep) < 0 ? plugin : undefined
}

/**
* Emits a change in the `Minimap` corresponding to the
* passed-in decoration.
Expand Down Expand Up @@ -608,6 +598,16 @@ export default class DecorationManagement {
}
}

function getOriginatorPackageName () {
const line = new Error().stack.split('\n')[3]
const filePath = line.split('(')[1].replace(')', '')
const re = new RegExp(
atom.packages.getPackageDirPaths().join('|') + escapeRegExp(path.sep)
)
const plugin = filePath.replace(re, '').split(path.sep)[0].replace(/minimap-|-minimap/, '')
return plugin.indexOf(path.sep) < 0 ? plugin : undefined
}

/**
* Given two ranges, it returns an array of ranges representing the
* differences between them.
Expand Down

0 comments on commit 3d67d03

Please sign in to comment.