Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix possibly cuttoff cli errors in tree views #4522

Merged
merged 7 commits into from
Aug 18, 2023
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
41 changes: 41 additions & 0 deletions extension/src/experiments/model/tree.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -637,5 +637,46 @@ describe('ExperimentsTree', () => {
iconPath: { id: 'circle-filled' }
})
})

it('should return a tree item for a cli error', () => {
const errorMsg = 'dvc cli error message'
const expectedUri = getDecoratableUri(
errorMsg,
DecoratableTreeItemScheme.EXPERIMENTS
)
const expectedCollapsibleState = 0

mockedGetMarkdownString.mockImplementationOnce(
str => str as unknown as MarkdownString
)
mockedTreeItem.mockImplementationOnce(function (uri, collapsibleState) {
expect(collapsibleState).toStrictEqual(expectedCollapsibleState)
expect(uri).toStrictEqual(expectedUri)
return { collapsibleState, uri }
})

const experimentsTree = new ExperimentsTree(
mockedExperiments,
mockedResourceLocator
)

const treeItem = experimentsTree.getTreeItem({
dvcRoot: 'repo',
error: errorMsg
})

expect(treeItem).toStrictEqual({
collapsibleState: expectedCollapsibleState,
command: {
command: RegisteredCommands.EXTENSION_SHOW_OUTPUT,
title: 'Show DVC Output'
},
contextValue: 'cliError',
iconPath: expect.anything(),
label: errorMsg,
tooltip: `$(error) ${errorMsg}`,
uri: expectedUri
})
})
})
})
8 changes: 5 additions & 3 deletions extension/src/experiments/model/tree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {
createTreeView,
DecoratableTreeItemScheme,
ErrorItem,
getCliErrorTreeItem,
getCliErrorMessageTreeItem,
getDecoratableTreeItem,
getErrorTooltip,
getRootItem,
Expand Down Expand Up @@ -88,14 +88,16 @@ export class ExperimentsTree
this.updateDescriptionOnChange()
}

public getTreeItem(element: string | ExperimentItem): TreeItem {
public getTreeItem(
element: string | ExperimentItem | ExperimentErrorItem
): TreeItem {
if (isRoot(element)) {
return getRootItem(element)
}

if (isExperimentErrorItem(element)) {
const { error } = element
return getCliErrorTreeItem(
return getCliErrorMessageTreeItem(
error,
error,
DecoratableTreeItemScheme.EXPERIMENTS
Expand Down
66 changes: 55 additions & 11 deletions extension/src/plots/paths/tree.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Uri } from 'vscode'
import { MarkdownString, TreeItem, Uri } from 'vscode'
import { Disposable, Disposer } from '@hediet/std/disposable'
import { EncodingType } from './collect'
import { PlotsPathsTree } from './tree'
Expand All @@ -9,11 +9,26 @@ import { Plots } from '..'
import { buildMockedEventEmitter } from '../../test/util/jest'
import { Shape, StrokeDash } from '../multiSource/constants'
import { join } from '../../test/util/path'
import { DecoratableTreeItemScheme, getDecoratableUri } from '../../tree'
import { RegisteredCommands } from '../../commands/external'
import { getMarkdownString } from '../../vscode/markdownString'

const mockedDisposable = jest.mocked(Disposable)
const mockedGetChildPaths = jest.fn()
const mockedWorkspacePlots = {
getRepository: () =>
({ getChildPaths: mockedGetChildPaths }) as unknown as Plots,
pathsChanged: buildMockedEventEmitter()
} as unknown as WorkspacePlots
const mockedInternalCommands = {
registerExternalCommand: jest.fn()
} as unknown as InternalCommands
const resourceLocator = new ResourceLocator(Uri.file(__filename))
const mockedTreeItem = jest.mocked(TreeItem)
const mockedGetMarkdownString = jest.mocked(getMarkdownString)

jest.mock('vscode')
jest.mock('../../vscode/markdownString')
jest.mock('@hediet/std/disposable')

beforeEach(() => {
Expand All @@ -27,16 +42,6 @@ beforeEach(() => {

describe('PlotsPathsTree', () => {
it('should return the correct children for multi source plots (encoding elements)', () => {
const mockedWorkspacePlots = {
getRepository: () =>
({ getChildPaths: mockedGetChildPaths }) as unknown as Plots,
pathsChanged: buildMockedEventEmitter()
} as unknown as WorkspacePlots
const mockedInternalCommands = {
registerExternalCommand: jest.fn()
} as unknown as InternalCommands
const resourceLocator = new ResourceLocator(Uri.file(__filename))

const plotsPathTree = new PlotsPathsTree(
mockedWorkspacePlots,
mockedInternalCommands,
Expand Down Expand Up @@ -86,4 +91,43 @@ describe('PlotsPathsTree', () => {
}
])
})

it('should return the correct tree item for a cli error', () => {
const errorMsg = 'dvc cli error message'
const path = join('plots', 'plot.png')
const expectedUri = getDecoratableUri(path, DecoratableTreeItemScheme.PLOTS)
const expectedCollapsibleState = 0

mockedGetMarkdownString.mockImplementationOnce(
str => str as unknown as MarkdownString
)
mockedTreeItem.mockImplementationOnce(function (uri, collapsibleState) {
expect(collapsibleState).toStrictEqual(expectedCollapsibleState)
expect(uri).toStrictEqual(expectedUri)
return { collapsibleState, uri }
})

const plotsPathTree = new PlotsPathsTree(
mockedWorkspacePlots,
mockedInternalCommands,
resourceLocator
)

const treeItem = plotsPathTree.getTreeItem({
error: errorMsg,
path
})

expect(treeItem).toStrictEqual({
collapsibleState: expectedCollapsibleState,
command: {
command: RegisteredCommands.EXTENSION_SHOW_OUTPUT,
title: 'Show DVC Output'
},
contextValue: 'cliError',
iconPath: expect.anything(),
tooltip: `$(error) ${errorMsg}`,
uri: expectedUri
})
})
})
23 changes: 14 additions & 9 deletions extension/src/repository/model/tree.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,6 @@ describe('RepositoriesTree', () => {
})

it('should return the correct tree item for an error', () => {
let mockedItem = {}
const label =
'ERROR: unable to read: params.yaml, YAML file structure is corrupted: mapping values are not allowed in this context'

Expand All @@ -386,13 +385,15 @@ describe('RepositoriesTree', () => {
mockedGetMarkdownString.mockImplementationOnce(
str => str as unknown as MarkdownString
)
const expectedUri = getDecoratableUri(
label,
DecoratableTreeItemScheme.TRACKED
)
const expectedCollapsibleState = 0
mockedTreeItem.mockImplementationOnce(function (uri, collapsibleState) {
expect(collapsibleState).toStrictEqual(0)
expect(uri).toStrictEqual(
getDecoratableUri(label, DecoratableTreeItemScheme.TRACKED)
)
mockedItem = { collapsibleState, uri }
return mockedItem
expect(collapsibleState).toStrictEqual(expectedCollapsibleState)
expect(uri).toStrictEqual(expectedUri)
return { collapsibleState, uri }
})

const trackedTreeView = new RepositoriesTree(
Expand All @@ -406,12 +407,16 @@ describe('RepositoriesTree', () => {

expect(mockedTreeItem).toHaveBeenCalledTimes(1)
expect(treeItem).toStrictEqual({
...mockedItem,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added tests for each tree that uses the cliError tree item and adjusted the check to not use mockedItem so we could confirm that label is or is not there.

collapsibleState: expectedCollapsibleState,
command: {
command: RegisteredCommands.EXTENSION_SHOW_OUTPUT,
title: 'Show DVC Output'
},
tooltip: `$(error) ${msg}`
contextValue: 'cliError',
iconPath: expect.anything(),
label,
tooltip: `$(error) ${msg}`,
uri: expectedUri
})
})
})
Expand Down
4 changes: 2 additions & 2 deletions extension/src/repository/model/tree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ import {
createTreeView,
DecoratableTreeItemScheme,
getCliErrorLabel,
getCliErrorTreeItem,
getCliErrorMessageTreeItem,
isErrorItem
} from '../../tree'
import { getWorkspaceFolders } from '../../vscode/workspaceFolders'
Expand Down Expand Up @@ -103,7 +103,7 @@ export class RepositoriesTree
if (isErrorItem(item)) {
const { error } = item

return getCliErrorTreeItem(
return getCliErrorMessageTreeItem(
getCliErrorLabel(error),
error,
DecoratableTreeItemScheme.TRACKED
Expand Down
13 changes: 13 additions & 0 deletions extension/src/tree/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,19 @@ export const getCliErrorTreeItem = (
command: RegisteredCommands.EXTENSION_SHOW_OUTPUT,
title: 'Show DVC Output'
}

return treeItem
}

export const getCliErrorMessageTreeItem = (
label: string,
msg: string,
decoratableTreeItemScheme: DecoratableTreeItemScheme
) => {
const treeItem = getCliErrorTreeItem(label, msg, decoratableTreeItemScheme)

treeItem.label = label
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the issue has something to do with the fact that we are creating a uri with the error message in the tree item which expects a file path 🤔

julieg18 marked this conversation as resolved.
Show resolved Hide resolved

return treeItem
}

Expand Down