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

Rename language association to recommend #902

Merged
merged 4 commits into from
Oct 13, 2021
Merged
Show file tree
Hide file tree
Changes from 3 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: 2 additions & 2 deletions extension/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ import {
showWalkthroughOnFirstUse
} from './vscode/walkthrough'
import { WorkspaceRepositories } from './repository/workspace'
import { tryAssociateYamlOnce } from './vscode/languageAssociation'
import { recommendAssociateYamlOnce } from './vscode/recommend'

export { Disposable, Disposer }

Expand Down Expand Up @@ -264,7 +264,7 @@ export class Extension implements IExtension {
)

showWalkthroughOnFirstUse(context.globalState)
this.dispose.track(tryAssociateYamlOnce())
this.dispose.track(recommendAssociateYamlOnce())
}

public async canRunCli(cwd: string) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ suite('Language Association Test Suite', () => {
restore()
})

describe('tryAssociateYamlOnce', () => {
describe('recommendAssociateYamlOnce', () => {
it('should only try and associate .dvc and dvc.lock files once per session', async () => {
const getUri = (fileName: string) => Uri.file(join(dvcDemoPath, fileName))

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { mocked } from 'ts-jest/utils'
import { window } from 'vscode'
import { getConfigValue, setUserConfigValue } from './config'
import { askUserToAssociateYaml } from './languageAssociation'
import { recommendAssociateYaml } from './recommend'

const mockedShowInformationMessage = jest.fn()
const mockedWindow = mocked(window)
Expand All @@ -17,10 +17,10 @@ beforeEach(() => {
jest.resetAllMocks()
})

describe('askUserToAssociateYaml', () => {
describe('recommendAssociateYaml', () => {
it('should set a user config option if the user responds with do not show again', async () => {
mockedShowInformationMessage.mockResolvedValueOnce("Don't Show Again")
await askUserToAssociateYaml()
await recommendAssociateYaml()

expect(mockedSetUserConfigValue).toBeCalledTimes(1)
expect(mockedSetUserConfigValue).toBeCalledWith(
Expand All @@ -34,7 +34,7 @@ describe('askUserToAssociateYaml', () => {
mockedGetConfigValue.mockReturnValueOnce({
'*.wat': 'perl'
})
await askUserToAssociateYaml()
await recommendAssociateYaml()

expect(mockedSetUserConfigValue).toBeCalledTimes(1)
expect(mockedSetUserConfigValue).toBeCalledWith('files.associations', {
Expand All @@ -46,14 +46,14 @@ describe('askUserToAssociateYaml', () => {

it('should not set any options if the user responds with no', async () => {
mockedShowInformationMessage.mockResolvedValueOnce('No')
await askUserToAssociateYaml()
await recommendAssociateYaml()

expect(mockedSetUserConfigValue).not.toBeCalled()
})

it('should not set any options if the user cancels the dialog', async () => {
mockedShowInformationMessage.mockResolvedValueOnce(undefined)
await askUserToAssociateYaml()
await recommendAssociateYaml()

expect(mockedSetUserConfigValue).not.toBeCalled()
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const addFileAssociations = () => {
return setUserConfigValue('files.associations', fileAssociations)
}

export const askUserToAssociateYaml = async () => {
export const recommendAssociateYaml = async () => {
const response = await getYesOrNoOrNever(
'Would you like to have "dvc.lock" and ".dvc" files recognized as YAML?'
)
Expand All @@ -47,14 +47,14 @@ const alreadyAssociated = (): boolean => {
)
}

export const tryAssociateYamlOnce = (): Disposable => {
export const recommendAssociateYamlOnce = (): Disposable => {
const singleUseListener = window.onDidChangeActiveTextEditor(editor => {
if (alreadyAssociated() || getConfigValue(doNotAssociateYaml)) {
return singleUseListener.dispose()
}

if (isFileType(editor?.document.fileName)) {
askUserToAssociateYaml()
recommendAssociateYaml()
return singleUseListener.dispose()
}
})
Expand Down