Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
module.exports = {
env: {
es6: true,
browser: true,
node: true,
jasmine: true,
atomtest: true,
},
extends: [
'standard',
],
globals: {
atom: 'readonly',
},
parserOptions: {
ecmaVersion: 2018,
},
rules: {
'no-warning-comments': 'warn',
'comma-dangle': ['error', 'always-multiline'],
indent: ['error', 'tab', { SwitchCase: 1 }],
'no-tabs': ['error', { allowIndentationTabs: true }],
'no-restricted-globals': [
'error',
{
name: 'fit',
message: 'Do not commit focused tests.',
},
{
name: 'fdescribe',
message: 'Do not commit focused tests.',
},
],
'no-sync': 'error',
},
}
74 changes: 74 additions & 0 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
name: "CI"
on:
pull_request:
push:
branches:
- master

env:
CI: true

jobs:
Test:
if: "!contains(github.event.head_commit.message, '[skip ci]')"
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
channel: [stable, beta]
fail-fast: false
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v1
- uses: UziTech/action-setup-atom@v1
with:
channel: ${{ matrix.channel }}
- name: Atom version
run: atom -v
- name: APM version
run: apm -v
- name: Install package dependencies
run: apm i minimap
- name: Install dependencies
run: apm ci
- name: Run tests 👩🏾‍💻
run: atom --test spec

Lint:
if: "!contains(github.event.head_commit.message, '[skip ci]')"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: actions/setup-node@v1
with:
node-version: '12.x'
- name: NPM install
run: npm ci
- name: Lint ✨
run: npm run lint

Release:
needs: [Test, Lint]
if: |
github.ref == 'refs/heads/master' &&
github.event.repository.fork == false
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: UziTech/action-setup-atom@v1
- uses: actions/setup-node@v1
with:
node-version: '12.x'
- name: NPM install
run: npm ci
- name: Release 🎉
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
ATOM_ACCESS_TOKEN: ${{ secrets.ATOM_ACCESS_TOKEN }}
run: npx semantic-release

Skip:
if: contains(github.event.head_commit.message, '[skip ci]')
runs-on: ubuntu-latest
steps:
- name: Skip CI 🚫
run: echo skip ci
8 changes: 0 additions & 8 deletions lib/helpers.coffee

This file was deleted.

11 changes: 11 additions & 0 deletions lib/helpers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const { Directory } = require('atom')

module.exports = {
repositoryForPath (goalPath) {
if (goalPath) {
const directory = new Directory(goalPath)
return atom.project.repositoryForDirectory(directory)
}
return Promise.resolve(null)
},
}
86 changes: 0 additions & 86 deletions lib/minimap-git-diff-binding.coffee

This file was deleted.

119 changes: 119 additions & 0 deletions lib/minimap-git-diff-binding.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
const { CompositeDisposable } = require('atom')
const { repositoryForPath } = require('./helpers')

class MinimapGitDiffBinding {
constructor (minimap) {
this.active = false
this.updateDiffs = this.updateDiffs.bind(this)
this.destroy = this.destroy.bind(this)
this.minimap = minimap
this.decorations = {}
this.markers = null
this.subscriptions = new CompositeDisposable()

if (!this.minimap) {
console.warn('minimap-git-diff binding created without a minimap')
return
}

this.editor = this.minimap.getTextEditor()

this.subscriptions.add(this.minimap.onDidDestroy(this.destroy))

this.getRepo().then(repo => {
this.repository = repo
if (repo) {
this.subscriptions.add(this.editor.getBuffer().onDidStopChanging(this.updateDiffs))
this.subscriptions.add(this.repository.onDidChangeStatuses(() => {
this.scheduleUpdate()
}))
this.subscriptions.add(this.repository.onDidChangeStatus(changedPath => {
if (changedPath === this.editor.getPath()) { this.scheduleUpdate() }
}))
this.subscriptions.add(this.repository.onDidDestroy(() => {
this.destroy()
}))
this.subscriptions.add(atom.config.observe('minimap-git-diff.useGutterDecoration', useGutterDecoration => {
this.useGutterDecoration = useGutterDecoration
this.scheduleUpdate()
}))
}
})

this.scheduleUpdate()
}

cancelUpdate () {
clearImmediate(this.immediateId)
}

scheduleUpdate () {
this.cancelUpdate()
this.immediateId = setImmediate(this.updateDiffs)
}

updateDiffs () {
this.removeDecorations()
if (this.getPath() && (this.diffs = this.getDiffs())) {
this.addDecorations(this.diffs)
}
}

addDecorations (diffs) {
for (const { newStart, oldLines, newLines } of Array.from(diffs)) {
const startRow = newStart - 1
const endRow = (newStart + newLines) - 2
if ((oldLines === 0) && (newLines > 0)) {
this.markRange(startRow, endRow, '.git-line-added')
} else if ((newLines === 0) && (oldLines > 0)) {
this.markRange(startRow, startRow, '.git-line-removed')
} else {
this.markRange(startRow, endRow, '.git-line-modified')
}
}
}

removeDecorations () {
if (!this.markers) { return }
for (const marker of Array.from(this.markers)) { marker.destroy() }
this.markers = null
}

markRange (startRow, endRow, scope) {
if (this.editor.isDestroyed()) { return }
const marker = this.editor.markBufferRange([[startRow, 0], [endRow, Infinity]], { invalidate: 'never' })
const type = this.useGutterDecoration ? 'gutter' : 'line'
this.minimap.decorateMarker(marker, { type, scope: `.minimap .${type} ${scope}`, plugin: 'git-diff' })
if (!this.markers) { this.markers = [] }
this.markers.push(marker)
}

destroy () {
this.removeDecorations()
this.subscriptions.dispose()
this.diffs = null
this.minimap = null
}

getPath () {
const buffer = this.editor.getBuffer()
if (buffer) {
return buffer.getPath()
}
}

getRepo () { return repositoryForPath(this.editor.getPath()) }

getDiffs () {
try {
const buffer = this.editor.getBuffer()
if (this.repository && buffer) {
return this.repository.getLineDiffs(this.getPath(), buffer.getText())
}
} catch (e) {}

return null
}
}

module.exports = MinimapGitDiffBinding
Loading