Skip to content

Commit

Permalink
Use type-fest’s Writable type
Browse files Browse the repository at this point in the history
  • Loading branch information
remcohaszing committed Dec 8, 2023
1 parent dc95bef commit ceda031
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 22 deletions.
21 changes: 17 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"monaco-editor": "^0.44.0",
"remark-cli": "^11.0.0",
"remark-preset-remcohaszing": "^2.0.0",
"type-fest": "^4.0.0",
"vitest": "^1.0.0"
}
}
5 changes: 2 additions & 3 deletions src/codeActionContext.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type * as monaco from 'monaco-types'
import { type Writable } from 'type-fest'
import type * as ls from 'vscode-languageserver-protocol'

import { fromCodeActionTriggerType } from './codeActionTriggerType.js'
Expand Down Expand Up @@ -50,9 +51,7 @@ export function toCodeActionContext(
codeActionContext: ls.CodeActionContext,
options?: ToCodeActionContextOptions
): monaco.languages.CodeActionContext {
const result: {
-readonly [K in keyof monaco.languages.CodeActionContext]: monaco.languages.CodeActionContext[K]
} = {
const result: Writable<monaco.languages.CodeActionContext> = {
markers: codeActionContext.diagnostics.map((diagnostic) => toMarkerData(diagnostic, options)),
trigger: fromCodeActionTriggerType(
codeActionContext.triggerKind ?? (2 satisfies monaco.languages.CodeActionTriggerType.Auto)
Expand Down
5 changes: 2 additions & 3 deletions src/semanticTokens.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type * as monaco from 'monaco-types'
import { type Writable } from 'type-fest'
import type * as ls from 'vscode-languageserver-protocol'

/**
Expand Down Expand Up @@ -34,9 +35,7 @@ export function fromSemanticTokens(
export function toSemanticTokens(
semanticTokens: ls.SemanticTokens
): monaco.languages.SemanticTokens {
const result: {
-readonly [K in keyof monaco.languages.SemanticTokens]: monaco.languages.SemanticTokens[K]
} = {
const result: Writable<monaco.languages.SemanticTokens> = {
data: Uint32Array.from(semanticTokens.data)
}

Expand Down
5 changes: 2 additions & 3 deletions src/semanticTokensEdit.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type * as monaco from 'monaco-types'
import { type Writable } from 'type-fest'
import type * as ls from 'vscode-languageserver-protocol'

/**
Expand Down Expand Up @@ -35,9 +36,7 @@ export function fromSemanticTokensEdit(
export function toSemanticTokensEdit(
semanticTokensEdit: ls.SemanticTokensEdit
): monaco.languages.SemanticTokensEdit {
const result: {
-readonly [K in keyof monaco.languages.SemanticTokensEdit]: monaco.languages.SemanticTokensEdit[K]
} = {
const result: Writable<monaco.languages.SemanticTokensEdit> = {
deleteCount: semanticTokensEdit.deleteCount,
start: semanticTokensEdit.start
}
Expand Down
9 changes: 3 additions & 6 deletions src/semanticTokensEdits.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type * as monaco from 'monaco-types'
import { type Writable } from 'type-fest'
import type * as ls from 'vscode-languageserver-protocol'

import { fromSemanticTokensEdit, toSemanticTokensEdit } from './semanticTokensEdit.js'
Expand All @@ -14,9 +15,7 @@ import { fromSemanticTokensEdit, toSemanticTokensEdit } from './semanticTokensEd
export function fromSemanticTokensEdits(
semanticTokensEdits: monaco.languages.SemanticTokensEdits
): ls.SemanticTokensDelta {
const result: {
-readonly [K in keyof ls.SemanticTokensDelta]: ls.SemanticTokensDelta[K]
} = {
const result: Writable<ls.SemanticTokensDelta> = {
edits: semanticTokensEdits.edits.map(fromSemanticTokensEdit)
}

Expand All @@ -38,9 +37,7 @@ export function fromSemanticTokensEdits(
export function toSemanticTokensEdits(
semanticTokensDelta: ls.SemanticTokensDelta
): monaco.languages.SemanticTokensEdits {
const result: {
-readonly [K in keyof monaco.languages.SemanticTokensEdits]: monaco.languages.SemanticTokensEdits[K]
} = {
const result: Writable<monaco.languages.SemanticTokensEdits> = {
edits: semanticTokensDelta.edits.map(toSemanticTokensEdit)
}

Expand Down
5 changes: 2 additions & 3 deletions src/signatureHelpContext.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type * as monaco from 'monaco-types'
import { type Writable } from 'type-fest'
import type * as ls from 'vscode-languageserver-protocol'

import { fromSignatureHelp, toSignatureHelp } from './signatureHelp.js'
Expand Down Expand Up @@ -42,9 +43,7 @@ export function fromSignatureHelpContext(
export function toSignatureHelpContext(
signatureHelpContext: ls.SignatureHelpContext
): monaco.languages.SignatureHelpContext {
const result: {
-readonly [K in keyof monaco.languages.SignatureHelpContext]: monaco.languages.SignatureHelpContext[K]
} = {
const result: Writable<monaco.languages.SignatureHelpContext> = {
isRetrigger: signatureHelpContext.isRetrigger,
triggerKind: fromSignatureHelpTriggerKind(signatureHelpContext.triggerKind)
}
Expand Down

0 comments on commit ceda031

Please sign in to comment.