Skip to content

Commit

Permalink
Prettier format
Browse files Browse the repository at this point in the history
  • Loading branch information
smolck committed May 15, 2021
1 parent e9f6469 commit be04d18
Show file tree
Hide file tree
Showing 19 changed files with 157 additions and 158 deletions.
2 changes: 1 addition & 1 deletion src/common/ipc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export const Events = {
modifyColorschemeLive: 'modifyColorschemeLive',
explorer: 'explorer',
updateNameplates: 'window.refresh',
lspDiagnostics: 'lspDiagnostics'
lspDiagnostics: 'lspDiagnostics',
} as const

export const RedrawEvents = {
Expand Down
31 changes: 16 additions & 15 deletions src/common/neovim-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,23 @@ export const FunctionGroup = () => {
const fns: string[] = []

const defineFunc: DefineFunction = onProp(
(name: PropertyKey) => (strParts: TemplateStringsArray, ...vars: any[]) => {
const expr = strParts
.map((m, ix) => [m, vars[ix]].join(''))
.join('')
.split('\n')
.filter((m) => m)
.map((m) => m.trim())
.join('\\n')
.replace(/"/g, '\\"')
(name: PropertyKey) =>
(strParts: TemplateStringsArray, ...vars: any[]) => {
const expr = strParts
.map((m, ix) => [m, vars[ix]].join(''))
.join('')
.split('\n')
.filter((m) => m)
.map((m) => m.trim())
.join('\\n')
.replace(/"/g, '\\"')

fns.push(
`exe ":fun! ${pascalCase(
name as string
)}(...) range\\n${expr}\\nendfun"`
)
}
fns.push(
`exe ":fun! ${pascalCase(
name as string
)}(...) range\\n${expr}\\nendfun"`
)
}
)

return {
Expand Down
18 changes: 8 additions & 10 deletions src/common/relative-finder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,14 @@ const distanceAsc = <T>(a: Distance<T>, b: Distance<T>) =>
const distanceDesc = <T>(a: Distance<T>, b: Distance<T>) =>
a.lines === b.lines ? a.characters > b.characters : a.lines > b.lines

const locationItemAsDistance = (line: number, column: number) => <
T extends LocationItem
>(
item: T
) =>
({
reference: item,
lines: item.range.start.line - line,
characters: item.range.start.character - column,
} as Distance<T>)
const locationItemAsDistance =
(line: number, column: number) =>
<T extends LocationItem>(item: T) =>
({
reference: item,
lines: item.range.start.line - line,
characters: item.range.start.character - column,
} as Distance<T>)

const findNextItem = <T extends LocationItem>(
items: T[],
Expand Down
38 changes: 23 additions & 15 deletions src/common/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,9 @@ const snakeCase = (m: string) =>
export const type = (m: any) =>
(Object.prototype.toString.call(m).match(/^\[object (\w+)\]/) ||
[])[1].toLowerCase()
export const within = (target: number, tolerance: number) => (
candidate: number
) => Math.abs(target - candidate) <= tolerance
export const within =
(target: number, tolerance: number) => (candidate: number) =>
Math.abs(target - candidate) <= tolerance
export const objToMap = (obj: object, map: Map<any, any>) =>
Object.entries(obj).forEach(([k, v]) => map.set(k, v))
export const listof = (count: number, fn: () => any) =>
Expand All @@ -91,8 +91,10 @@ export const merge = Object.assign
export const cc = (...a: any[]) => Promise.all(a)
export const delay = (t: number) => new Promise((d) => setTimeout(d, t))
export const ID = (val = 0) => ({ next: () => (val++, val) })
export const $ = <T>(...fns: Function[]) => (...a: any[]) =>
(fns.reduce((res, fn, ix) => (ix ? fn(res) : fn(...res)), a) as unknown) as T
export const $ =
<T>(...fns: Function[]) =>
(...a: any[]) =>
fns.reduce((res, fn, ix) => (ix ? fn(res) : fn(...res)), a) as unknown as T
export const is = new Proxy<Types>({} as Types, {
get: (_, key) => (val: any) => type(val) === key,
})
Expand All @@ -101,7 +103,12 @@ export const onProp = <T>(cb: (name: PropertyKey) => void): T =>
export const onFnCall = <T>(cb: (name: string, args: any[]) => void): T =>
new Proxy(
{},
{ get: (_, name) => (...args: any[]) => cb(name as string, args) }
{
get:
(_, name) =>
(...args: any[]) =>
cb(name as string, args),
}
) as T
export const pascalCase = (m: string) => m[0].toUpperCase() + m.slice(1)
export const camelCase = (m: string) => m[0].toLowerCase() + m.slice(1)
Expand Down Expand Up @@ -153,9 +160,11 @@ export const genList = <T>(count: number, fn: (index: number) => T) => {
return resultList
}

export const minmax = (min: number, max: number) => (...numbers: number[]) => {
return Math.min(max, Math.max(min, ...numbers))
}
export const minmax =
(min: number, max: number) =>
(...numbers: number[]) => {
return Math.min(max, Math.max(min, ...numbers))
}

export const pathRelativeTo = (path: string, otherPath: string) =>
path.includes(otherPath)
Expand Down Expand Up @@ -192,8 +201,10 @@ export const pathReducer = (p = '') =>
: (levels++, basename(p)),
}))(p)

export const matchOn = (val: any) => (opts: object): any =>
(Reflect.get(opts, val) || (() => {}))()
export const matchOn =
(val: any) =>
(opts: object): any =>
(Reflect.get(opts, val) || (() => {}))()

export const isOnline = (host = 'google.com') =>
new Promise((fin) => {
Expand Down Expand Up @@ -536,10 +547,7 @@ export class Watchers extends Map<string, Set<Function>> {
add(event: string, handler: (data: any) => void) {
this.has(event)
? this.get(event)!.add(handler)
: this.set(
event,
new Set<Function>([handler])
)
: this.set(event, new Set<Function>([handler]))
}

notify(event: string, ...args: any[]) {
Expand Down
9 changes: 2 additions & 7 deletions src/main/core/instance-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,8 @@ import { Events } from '../../common/ipc'

const InstanceApi = (workerInstanceRef: Worker, winRef: BrowserWindow) => {
const ee = new EventEmitter()
const {
state,
watchState,
onStateValue,
onStateChange,
untilStateValue,
} = NeovimState('nvim-mirror')
const { state, watchState, onStateValue, onStateChange, untilStateValue } =
NeovimState('nvim-mirror')

const actionRegistrations: string[] = []
if (actionRegistrations.length)
Expand Down
6 changes: 4 additions & 2 deletions src/main/core/redraw.ts
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,8 @@ export const handleRedraw = (
// Done a lot here since then perhaps . . .
if (e === 'grid_line') sendToRenderer(RedrawEvents.gridLine, ev)
// TODO(smolck): Really hope this doesn't need to be handled here
else if (e === 'flush') (winUpdates = true, sendToRenderer(RedrawEvents.flush))
else if (e === 'flush')
(winUpdates = true), sendToRenderer(RedrawEvents.flush)
else if (e === 'grid_scroll') sendToRenderer(RedrawEvents.gridScroll, ev)
else if (e === 'grid_cursor_goto') grid_cursor_goto(ev, sendToRenderer)
else if (e === 'win_pos') (winUpdates = true), win_pos(ev, sendToRenderer)
Expand All @@ -320,7 +321,8 @@ export const handleRedraw = (
else if (e === 'grid_destroy') sendToRenderer(RedrawEvents.gridDestroy, ev)
else if (e === 'tabline_update') tabline_update(ev, sendToRenderer)
// TODO(smolck): call mode_change and send to renderer?
else if (e === 'mode_change') (mode_change(ev, nvim), sendToRenderer(RedrawEvents.modeChange, ev))
else if (e === 'mode_change')
mode_change(ev, nvim), sendToRenderer(RedrawEvents.modeChange, ev)
else if (e === 'popupmenu_hide') sendToRenderer(RedrawEvents.pmenuHide)
else if (e === 'popupmenu_select')
sendToRenderer(RedrawEvents.pmenuSelect, ev[1][0])
Expand Down
28 changes: 15 additions & 13 deletions src/main/neovim/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,19 +76,21 @@ const StateConstructor = (_stateName: string) => {
}

const onStateValue: OnStateValue = new Proxy(Object.create(null), {
get: (_, key: string) => (matchValue: any, ...args: any[]) => {
const matchPreviousValue = args.find((a) => typeof a === 'string')
const fn = args.find((a) => typeof a === 'function')

watchers.on(key, (value, previousValue) => {
const same = value === matchValue
const prevSame =
typeof matchPreviousValue == null
? true
: previousValue === matchPreviousValue
if (same && prevSame) fn()
})
},
get:
(_, key: string) =>
(matchValue: any, ...args: any[]) => {
const matchPreviousValue = args.find((a) => typeof a === 'string')
const fn = args.find((a) => typeof a === 'function')

watchers.on(key, (value, previousValue) => {
const same = value === matchValue
const prevSame =
typeof matchPreviousValue == null
? true
: previousValue === matchPreviousValue
if (same && prevSame) fn()
})
},
})

const untilStateValue: UntilStateValue = new Proxy(Object.create(null), {
Expand Down
3 changes: 2 additions & 1 deletion src/main/process-explorer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ interface ProcessItem extends ProcessStats {

const MB = 1024 * 1024
const CMD = '/bin/ps -ax -o pid=,ppid=,pcpu=,pmem=,command='
const PID_CMD = /^\s*([0-9]+)\s+([0-9]+)\s+([0-9]+\.[0-9]+)\s+([0-9]+\.[0-9]+)\s+(.+)$/
const PID_CMD =
/^\s*([0-9]+)\s+([0-9]+)\s+([0-9]+\.[0-9]+)\s+([0-9]+\.[0-9]+)\s+(.+)$/
const usageHistory = new Map<number, ProcessHistory>()
const container = document.getElementById('process-list') as HTMLElement
const historyContainer = document.getElementById(
Expand Down
4 changes: 3 additions & 1 deletion src/main/services/buffer-search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ export const fuzzy = async (
export const fuzzyVisible = async (query: string): Promise<FilterResult[]> => {
const { editorTopLine: start, editorBottomLine: end } = nvim.state
// TODO(smolck): `end + 1` or just `end`?
const visibleLines = await (await nvim.buffer).getLines({
const visibleLines = await (
await nvim.buffer
).getLines({
start,
end: end + 1,
strictIndexing: true,
Expand Down
19 changes: 4 additions & 15 deletions src/main/workers/neovim-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,8 @@ if (!workerData || !workerData.nvimPath)
)}`
)

const {
state,
watchState,
onStateChange,
onStateValue,
untilStateValue,
} = NvimState('main')
const { state, watchState, onStateChange, onStateValue, untilStateValue } =
NvimState('main')

const watchers = {
actions: new EventEmitter(),
Expand Down Expand Up @@ -294,14 +289,8 @@ nvimInstance.on('nvim_buf_changedtick_event', (args: any[]) => {

nvimInstance.subscribe('nvim_buf_lines_event')
nvimInstance.on('nvim_buf_lines_event', (args: any[]) => {
const [
extContainerData,
changedTick,
firstLine,
lastLine,
lineData,
more,
] = args
const [extContainerData, changedTick, firstLine, lastLine, lineData, more] =
args
const bufId = extContainerData.id

watchers.bufferEvents.emit(`change:${bufId}`, {
Expand Down
9 changes: 5 additions & 4 deletions src/renderer/components/extensions/legacy/buffer-search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,11 @@ const actions = {
if (!res.length) return a.updateResults([])

const textLines = res.map((m) => m.line)
const coloredLines: ColorData[][] = await colorizer.request.colorizePerChar(
textLines,
api.nvim.state.filetype
)
const coloredLines: ColorData[][] =
await colorizer.request.colorizePerChar(
textLines,
api.nvim.state.filetype
)

const lines = coloredLines
.filter((m) => m.length)
Expand Down
6 changes: 2 additions & 4 deletions src/renderer/components/extensions/legacy/grep.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,8 @@ type S = typeof state
// scroll after next section has been rendered as expanded (a little hacky)
const scrollIntoView = (next: number) =>
setTimeout(() => {
const {
top: containerTop,
bottom: containerBottom,
} = elref.getBoundingClientRect()
const { top: containerTop, bottom: containerBottom } =
elref.getBoundingClientRect()
const e = els.get(next)
if (!e) return

Expand Down
12 changes: 4 additions & 8 deletions src/renderer/components/extensions/lsp-references.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,8 @@ type S = typeof state
// scroll after next section has been rendered as expanded (a little hacky)
const scrollIntoView = (next: number) =>
setTimeout(() => {
const {
top: containerTop,
bottom: containerBottom,
} = elref.getBoundingClientRect()
const { top: containerTop, bottom: containerBottom } =
elref.getBoundingClientRect()
const e = els.get(next)
if (!e) return

Expand All @@ -55,10 +53,8 @@ const scrollIntoView = (next: number) =>

const scrollSubitemsIntoView = (parentIx: number, next: number) =>
setTimeout(() => {
const {
top: containerTop,
bottom: containerBottom,
} = elref.getBoundingClientRect()
const { top: containerTop, bottom: containerBottom } =
elref.getBoundingClientRect()
const e = els.get(parentIx)?.children[1].children[next]
if (!e) return

Expand Down
7 changes: 1 addition & 6 deletions src/renderer/components/nvim/message-history.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,7 @@ const getIcon = (kind: MessageKind) =>

const WhyDiv = (props: any) => <div {...props}>{props.children}</div>

const MessageHistory = ({
vis: visible,
messages,
ix: index,
query,
}: S) => (
const MessageHistory = ({ vis: visible, messages, ix: index, query }: S) => (
<div
style={{
background: 'var(--background-45)',
Expand Down
4 changes: 3 additions & 1 deletion src/renderer/components/nvim/statusline.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,9 @@ sub('message.control', (msg) => assignStateAndRender({ controlMessage: msg }))
window.api.on(Events.lspDiagnostics, (diagnostics) => {
let errors = 0
let warnings = 0
diagnostics.forEach((d: any) => d.severity === 1 ? errors += 1 : d.severity === 2 ? warnings += 1 : {})
diagnostics.forEach((d: any) =>
d.severity === 1 ? (errors += 1) : d.severity === 2 ? (warnings += 1) : {}
)
assignStateAndRender({ errors, warnings })
})

Expand Down
15 changes: 10 additions & 5 deletions src/renderer/render/redraw.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
import {
addHighlight,
setDefaultColors,
} from './highlight-attributes'
import { addHighlight, setDefaultColors } from './highlight-attributes'
import * as windows from '../windows/window-manager'
import * as dispatch from '../dispatch'
import { RedrawEvents, Invokables } from '../../common/ipc'
Expand Down Expand Up @@ -194,7 +191,15 @@ handle.gridCursorGoto((gridId, row, col) => {
})
handle.gridScroll(([, [gridId, top, bottom, left, right, rows, cols]]) => {
// if (gridId === 1) return
windows.renderer.handlers.grid_scroll(gridId, top, bottom, left, right, rows, cols)
windows.renderer.handlers.grid_scroll(
gridId,
top,
bottom,
left,
right,
rows,
cols
)
})
handle.gridClear(grid_clear)
handle.gridDestroy(grid_destroy)
Expand Down
Loading

0 comments on commit be04d18

Please sign in to comment.