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

Add commands to jump to previous/next error #2526

Merged
merged 4 commits into from
Aug 29, 2018
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
PR feedback
  • Loading branch information
psxpaul committed Aug 28, 2018
commit 8a224e82b1d99e42e3296fb4280f61348589f552
78 changes: 1 addition & 77 deletions browser/src/Services/Commands/GlobalCommands.ts
Original file line number Diff line number Diff line change
@@ -9,17 +9,13 @@ import { remote } from "electron"

import * as Oni from "oni-api"

import {
getAllErrorsForFile,
getInstance as getDiagnosticsInstance,
} from "./../../Services/Diagnostics"
import { gotoNextError, gotoPreviousError } from "./../../Services/Diagnostics/navigateErrors"
import { EditorManager } from "./../../Services/EditorManager"
import { MenuManager } from "./../../Services/Menu"
import { showAboutMessage } from "./../../Services/Metadata"
import { multiProcess } from "./../../Services/MultiProcess"
import { Tasks } from "./../../Services/Tasks"
import { windowManager } from "./../../Services/WindowManager"
import { isInRange } from "./../../Utility"

// import * as UI from "./../UI/index"

@@ -50,78 +46,6 @@ export const activate = (
const popupMenuPrevious = popupMenuCommand(() => menuManager.previousMenuItem())
const popupMenuSelect = popupMenuCommand(() => menuManager.selectMenuItem())

const gotoNextError = async () => {
const errors = getDiagnosticsInstance().getErrors()
const activeBuffer = editorManager.activeEditor.activeBuffer
const currentFileErrors = getAllErrorsForFile(activeBuffer.filePath, errors)
const currentPosition = activeBuffer.cursor

if (!currentFileErrors || currentFileErrors.length === 0) {
return
}

for (const error of currentFileErrors) {
if (isInRange(currentPosition.line, currentPosition.column, error.range)) {
continue
}

const currentLine = (await activeBuffer.getLines(currentPosition.line))[0]
if (
currentPosition.line === error.range.start.line &&
currentLine.length <= error.range.start.character
) {
continue
}

if (
error.range.start.line > currentPosition.line ||
(error.range.start.line === currentPosition.line &&
error.range.start.character > currentPosition.column)
) {
await activeBuffer.setCursorPosition(
error.range.start.line,
error.range.start.character,
)
return
}
}

activeBuffer.setCursorPosition(
currentFileErrors[0].range.start.line,
currentFileErrors[0].range.start.character,
)
}

const gotoPreviousError = async () => {
const errors = getDiagnosticsInstance().getErrors()
const activeBuffer = editorManager.activeEditor.activeBuffer
const currentFileErrors = getAllErrorsForFile(activeBuffer.filePath, errors)
const currentPosition = activeBuffer.cursor

if (!currentFileErrors || currentFileErrors.length === 0) {
return
}

let lastError = currentFileErrors[currentFileErrors.length - 1]
for (const error of currentFileErrors) {
if (
isInRange(currentPosition.line, currentPosition.column, error.range) ||
error.range.start.line > currentPosition.line ||
(error.range.start.line === currentPosition.line &&
error.range.start.character > currentPosition.column)
) {
await activeBuffer.setCursorPosition(
lastError.range.start.line,
lastError.range.start.character,
)
return
}
lastError = error
}

activeBuffer.setCursorPosition(lastError.range.start.line, lastError.range.start.character)
}

const commands = [
new CallbackCommand("editor.executeVimCommand", null, null, (message: string) => {
const neovim = editorManager.activeEditor.neovim
83 changes: 83 additions & 0 deletions browser/src/Services/Diagnostics/navigateErrors.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/**
* navigateErrors.ts
*
* Functions to jump to previous/next diagnostic error in the active buffer
*/
import { isInRange } from "./../../Utility"
import { getAllErrorsForFile, getInstance as getDiagnosticsInstance } from "./../Diagnostics"
import { editorManager } from "./../EditorManager"

export const gotoNextError = async () => {
const errors = getDiagnosticsInstance().getErrors()
const activeBuffer = editorManager.activeEditor.activeBuffer
const currentFileErrors = getAllErrorsForFile(activeBuffer.filePath, errors)
const currentPosition = activeBuffer.cursor

if (!currentFileErrors) {
return
}

for (const error of currentFileErrors) {
if (isInRange(currentPosition.line, currentPosition.column, error.range)) {
continue
}

const currentLine = (await activeBuffer.getLines(currentPosition.line))[0]
if (
currentPosition.line === error.range.start.line &&
currentLine.length <= error.range.start.character
) {
continue
}

if (
error.range.start.line > currentPosition.line ||
(error.range.start.line === currentPosition.line &&
error.range.start.character > currentPosition.column)
) {
await activeBuffer.setCursorPosition(
error.range.start.line,
error.range.start.character,
)
return
}
}

await activeBuffer.setCursorPosition(
currentFileErrors[0].range.start.line,
currentFileErrors[0].range.start.character,
)
}

export const gotoPreviousError = async () => {
const errors = getDiagnosticsInstance().getErrors()
const activeBuffer = editorManager.activeEditor.activeBuffer
const currentFileErrors = getAllErrorsForFile(activeBuffer.filePath, errors)
const currentPosition = activeBuffer.cursor

if (!currentFileErrors) {
return
}

let lastError = currentFileErrors[currentFileErrors.length - 1]
for (const error of currentFileErrors) {
if (
isInRange(currentPosition.line, currentPosition.column, error.range) ||
error.range.start.line > currentPosition.line ||
(error.range.start.line === currentPosition.line &&
error.range.start.character > currentPosition.column)
) {
await activeBuffer.setCursorPosition(
lastError.range.start.line,
lastError.range.start.character,
)
return
}
lastError = error
}

await activeBuffer.setCursorPosition(
lastError.range.start.line,
lastError.range.start.character,
)
}