Skip to content
This repository has been archived by the owner on Apr 1, 2020. It is now read-only.

[WIP] Feature/import cost layer #2506

Open
wants to merge 18 commits into
base: master
Choose a base branch
from
Open
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
4 changes: 4 additions & 0 deletions browser/src/App.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/

import { ipcRenderer, remote } from "electron"
import { EventEmitter } from "events"
import * as fs from "fs"
import * as minimist from "minimist"
import * as path from "path"
Expand All @@ -17,6 +18,9 @@ import * as Utility from "./Utility"

import { IConfigurationValues } from "./Services/Configuration/IConfigurationValues"

// Increase default max listeners
EventEmitter.defaultMaxListeners = 30

const editorManagerPromise = import("./Services/EditorManager")
const sharedNeovimInstancePromise = import("./neovim/SharedNeovimInstance")

Expand Down
12 changes: 5 additions & 7 deletions browser/src/Editor/NeovimEditor/BufferLayerManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,6 @@ export class BufferLayerManager {
}
}

const getInstance = (() => {
const instance = new BufferLayerManager()
return () => instance
})()

export default getInstance

export const wrapReactComponentWithLayer = (
id: string,
component: JSX.Element,
Expand All @@ -85,3 +78,8 @@ export const wrapReactComponentWithLayer = (
render: (context: Oni.BufferLayerRenderContext) => (context.isActive ? component : null),
}
}

const instance = new BufferLayerManager()
const getInstance = () => instance

export default getInstance
1 change: 1 addition & 0 deletions browser/src/Services/Configuration/DefaultConfiguration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ const BaseConfiguration: IConfigurationValues = {
"experimental.vcs.blame.mode": "auto",
"experimental.vcs.blame.timeout": 800,

"layers.priority": ["import-costs", "vcs.blame"],
"experimental.colorHighlight.enabled": false,
"experimental.colorHighlight.filetypes": [
".css",
Expand Down
5 changes: 5 additions & 0 deletions browser/src/Services/Configuration/IConfigurationValues.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ export interface IConfigurationValues {
// - textMateHighlighting
"editor.textMateHighlighting.enabled": boolean

// A list of oni bufferlayer IDs, the ids order in this array determines their priority,
// the first element has the highest priority so if there is
// a clash the first buffer layer element will render
"layers.priority": string[]

// Whether or not the learning pane is available
"experimental.particles.enabled": boolean

Expand Down
25 changes: 20 additions & 5 deletions browser/src/Services/VersionControl/VersionControlBlameLayer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ interface IBlamePosition {
top: number
left: number
hide: boolean
leftOffset: number
}

interface ICanFit {
Expand All @@ -32,6 +33,7 @@ interface ILineDetails {

export interface IProps extends LayerContextWithCursor {
getBlame: (lineOne: number, lineTwo: number) => Promise<IBlame>
priority: number
timeout: number
cursorScreenLine: number
cursorBufferLine: number
Expand All @@ -55,7 +57,9 @@ interface IContainerProps {
left: number
fontFamily: string
hide: boolean
priority: number
timeout: number
leftOffset: number
animationState: TransitionStates
}

Expand All @@ -69,9 +73,10 @@ const getOpacity = (state: TransitionStates) => {
}

export const BlameContainer = withProps<IContainerProps>(styled.div).attrs({
style: ({ top, left }: IContainerProps) => ({
style: ({ top, left, leftOffset }: IContainerProps) => ({
top: pixel(top),
left: pixel(left),
paddingLeft: pixel(leftOffset),
}),
})`
${p => p.hide && `visibility: hidden`};
Expand All @@ -86,6 +91,7 @@ export const BlameContainer = withProps<IContainerProps>(styled.div).attrs({
height: ${p => pixel(p.height)};
line-height: ${p => pixel(p.height)};
right: 3em;
z-index: ${p => p.priority};
${textOverflow}
`

Expand Down Expand Up @@ -201,10 +207,10 @@ export class Blame extends React.PureComponent<IProps, IState> {
public calculatePosition(canFit: boolean) {
const { cursorLine, cursorScreenLine, visibleLines } = this.props
const currentLine = visibleLines[cursorScreenLine]
const character = currentLine && currentLine.length + this.LEFT_OFFSET
const character = currentLine && currentLine.length

if (canFit) {
return this.getPosition({ line: cursorLine, character })
return this.getPosition({ line: cursorLine, character }, canFit)
}

const { lastEmptyLine, nextSpacing } = this.getLastEmptyLine()
Expand All @@ -228,23 +234,27 @@ export class Blame extends React.PureComponent<IProps, IState> {
return new Date(parseInt(timestamp, 10) * 1000)
}

public getPosition(positionToRender?: Position): IBlamePosition {
public getPosition(positionToRender?: Position, canFit: boolean = false): IBlamePosition {
const emptyPosition: IBlamePosition = {
hide: true,
top: null,
left: null,
leftOffset: null,
}
if (!positionToRender) {
return emptyPosition
}

const position = this.props.bufferToPixel(positionToRender)

if (!position) {
return emptyPosition
}
return {
hide: false,
top: position.pixelY,
left: position.pixelX,
leftOffset: canFit ? this.LEFT_OFFSET * this.props.fontPixelWidth : 0,
}
}

Expand Down Expand Up @@ -309,6 +319,7 @@ export class Blame extends React.PureComponent<IProps, IState> {
data-id="vcs.blame"
timeout={this.DURATION}
animationState={state}
priority={this.props.priority}
height={this.props.fontPixelHeight}
fontFamily={this.props.fontFamily}
>
Expand Down Expand Up @@ -354,8 +365,11 @@ export default class VersionControlBlameLayer implements BufferLayer {
const fontFamily = this._configuration.getValue<string>("editor.fontFamily")
const timeout = this._configuration.getValue<number>("experimental.vcs.blame.timeout")
const mode = this._configuration.getValue<"auto" | "manual">("experimental.vcs.blame.mode")
const priorities = this._configuration.getValue<string[]>("layers.priority", [])
const index = priorities.indexOf(this.id)
const priority = index >= 0 ? priorities.length - index : 0

return { timeout, mode, fontFamily }
return { timeout, mode, fontFamily, priority }
}

public render(context: LayerContextWithCursor) {
Expand All @@ -368,6 +382,7 @@ export default class VersionControlBlameLayer implements BufferLayer {
<Blame
{...context}
mode={config.mode}
priority={config.priority}
timeout={config.timeout}
getBlame={this.getBlame}
fontFamily={config.fontFamily}
Expand Down
29 changes: 29 additions & 0 deletions extensions/oni-plugin-import-cost/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"name": "oni-plugin-import-cost",
"version": "1.0.0",
"description": "An import cost buffer layer for Oni",
"main": "lib/index.js",
"author": "A. Sowemimo",
"license": "MIT",
"engines": {
"oni": "^0.2.6"
},
"scripts": {
"build": "rimraf lib && tsc",
"test": "jest"
},
"dependencies": {
"import-cost": "^1.5.0",
"oni-api": "^0.0.46",
"oni-types": "^0.0.8",
"react": "^16.4.2"
},
"devDependencies": {
"rimraf": "^2.6.2",
"typescript": "^2.9.2"
},
"peerDependencies": {
"jest": "^23.5.0",
"styled-components": "^3.2.6"
}
}
Loading