Skip to content

Commit

Permalink
Merge pull request #2936 from opral/felixhaeberle/sherl-79-ship-defau…
Browse files Browse the repository at this point in the history
…lt-human-ids-in-sherlock-already

ship default human ids in sherlock already | Sherlock 🕵️‍♂️
  • Loading branch information
felixhaeberle authored Jun 17, 2024
2 parents a2ab282 + eff7f4f commit 3eb63c5
Show file tree
Hide file tree
Showing 8 changed files with 109 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/thirty-cobras-own.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"vs-code-extension": minor
---

default human ids in sherlock
12 changes: 12 additions & 0 deletions inlang/source-code/ide-extension/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,18 @@ You can disable inline annotations by setting the following property to `false`
"sherlock.inlineAnnotations.enabled": false
```

### Disable Auto Human ID Generation

You can disable the automatic generation of human IDs by setting the following property to `false` in your VS Code `settings.json` file. The default value is `true`.

```json
"sherlock.extract.autoHumanId.enabled": false
```

> [!NOTE]
> Tip: It's best practice to use random names for your messages. Read this [guide](https://inlang.com/documentation/concept/message#idhuman-readable) for more information.

#### Troubleshooting

If you are having trouble with the **loading icon** not disappearing, this is a known issue & we are working with Visual Studio Code to fix it. In the meantime, you can right-click the Inlang icon to hide it:
Expand Down
13 changes: 12 additions & 1 deletion inlang/source-code/ide-extension/docs/customization.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,15 @@ You can disable inline annotations by setting the following property to `false`

```json
"sherlock.inlineAnnotations.enabled": false
```
```

## Disable Auto Human ID Generation

You can disable the automatic generation of human IDs by setting the following property to `false` in your VS Code `settings.json` file. The default value is `true`.

```json
"sherlock.extract.autoHumanId.enabled": false
```

> [!NOTE]
> Tip: It's best practice to use random names for your messages. Read this [guide](https://inlang.com/documentation/concept/message#idhuman-readable) for more information.
14 changes: 14 additions & 0 deletions inlang/source-code/ide-extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,20 @@
}
}
},
"sherlock.extract": {
"type": "object",
"properties": {
"autoHumanId": {
"type": "object",
"properties": {
"enabled": {
"type": "boolean",
"default": true
}
}
}
}
},
"sherlock.inlineAnnotations.enabled": {
"type": "boolean",
"default": true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import { msg } from "../utilities/messages/msg.js"
import { window } from "vscode"
import { telemetry } from "../services/telemetry/index.js"
import { CONFIGURATION } from "../configuration.js"
import { getSetting } from "../utilities/settings/index.js"
import { randomHumanId } from "@inlang/sdk"

vi.mock("vscode", () => ({
commands: {
Expand Down Expand Up @@ -40,6 +42,14 @@ vi.mock("../configuration", () => ({
},
}))

vi.mock("../utilities/settings/index", () => ({
getSetting: vi.fn(),
}))

vi.mock("@inlang/sdk", () => ({
randomHumanId: vi.fn(() => "randomHumanId123"),
}))

describe("createMessageCommand", () => {
const mockState = {
project: {
Expand All @@ -57,6 +67,9 @@ describe("createMessageCommand", () => {
vi.resetAllMocks()
// @ts-expect-error
state.mockReturnValue(mockState)

// Mock getSetting only for this test
vi.mocked(getSetting).mockResolvedValueOnce(true)
})

afterEach(() => {
Expand Down Expand Up @@ -98,7 +111,7 @@ describe("createMessageCommand", () => {
await createMessageCommand.callback()

expect(window.showInputBox).toHaveBeenCalledWith({
title: "Enter the ID:",
title: "Enter the message content:",
})
expect(msg).not.toHaveBeenCalled()
})
Expand Down Expand Up @@ -153,4 +166,37 @@ describe("createMessageCommand", () => {
})
expect(msg).toHaveBeenCalledWith("Message created.")
})

it("should use randomHumanId as default messageId if autoHumanId is true", async () => {
mockState.project.settings.mockReturnValueOnce({ sourceLanguageTag: "en" })
// @ts-expect-error
window.showInputBox.mockResolvedValueOnce("Message content")
// @ts-expect-error
getSetting.mockResolvedValueOnce(true)
// @ts-expect-error
window.showInputBox.mockResolvedValueOnce("randomHumanId123")

await createMessageCommand.callback()

expect(randomHumanId).toHaveBeenCalled()
expect(window.showInputBox).toHaveBeenCalledWith({
title: "Enter the message content:",
})
})

it("should not use randomHumanId as default messageId if autoHumanId is false", async () => {
mockState.project.settings.mockReturnValueOnce({ sourceLanguageTag: "en" })
// @ts-expect-error
window.showInputBox.mockResolvedValueOnce("Message content")
// @ts-expect-error
getSetting.mockResolvedValueOnce(false)
// @ts-expect-error
window.showInputBox.mockResolvedValueOnce("")

await createMessageCommand.callback()

expect(window.showInputBox).toHaveBeenCalledWith({
title: "Enter the message content:",
})
})
})
10 changes: 9 additions & 1 deletion inlang/source-code/ide-extension/src/commands/createMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ import { state } from "../utilities/state.js"
import { msg } from "../utilities/messages/msg.js"
import { commands, window } from "vscode"
import { telemetry } from "../services/telemetry/index.js"
import type { Message } from "@inlang/sdk"
import { randomHumanId, type Message } from "@inlang/sdk"
import { CONFIGURATION } from "../configuration.js"
import { getSetting } from "../utilities/settings/index.js"

/**
* Helps the user to create messages by prompting for the message content.
Expand Down Expand Up @@ -31,8 +32,15 @@ export const createMessageCommand = {
return
}

// create random message id as default value
const autoHumanId = await getSetting("extract.autoHumanId.enabled").catch(() => true)

const messageId = await window.showInputBox({
title: "Enter the ID:",
value: autoHumanId ? randomHumanId() : "",
prompt:
autoHumanId &&
"Tip: It's best practice to use random names for your messages. Read this [guide](https://inlang.com/documentation/concept/message#idhuman-readable) for more information.",
})
if (messageId === undefined) {
return
Expand Down
10 changes: 9 additions & 1 deletion inlang/source-code/ide-extension/src/commands/extractMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ import { state } from "../utilities/state.js"
import { msg } from "../utilities/messages/msg.js"
import { commands, type TextEditor, window } from "vscode"
import { telemetry } from "../services/telemetry/index.js"
import type { Message } from "@inlang/sdk"
import { CONFIGURATION } from "../configuration.js"
import { isQuoted, stripQuotes } from "../utilities/messages/isQuoted.js"
import { Message, randomHumanId } from "@inlang/sdk"
import { getSetting } from "../utilities/settings/index.js"

/**
* Helps the user to extract messages from the active text editor.
Expand Down Expand Up @@ -52,8 +53,15 @@ export const extractMessageCommand = {
return msg("Please select a text to extract in your text editor.", "warn", "notification")
}

// create random message id as default value
const autoHumanId = await getSetting("extract.autoHumanId.enabled").catch(() => true)

const messageId = await window.showInputBox({
title: "Enter the ID:",
value: autoHumanId ? randomHumanId() : "",
prompt:
autoHumanId &&
"Tip: It's best practice to use random names for your messages. Read this [guide](https://inlang.com/documentation/concept/message#idhuman-readable) for more information.",
})
if (messageId === undefined) {
return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const settingsProperty = [
"editorColors.error.foreground",
"editorColors.error.background",
"editorColors.error.border",
"extract.autoHumanId.enabled",
"inlineAnnotations.enabled",
] as const

Expand Down

0 comments on commit 3eb63c5

Please sign in to comment.