Skip to content

Commit

Permalink
Add support for YAML selection ranges
Browse files Browse the repository at this point in the history
  • Loading branch information
remcohaszing committed Jun 7, 2024
1 parent a255d0e commit 32bb27e
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
6 changes: 3 additions & 3 deletions package-lock.json

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

13 changes: 13 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
toLink,
toLocationLink,
toMarkerData,
toSelectionRanges,
toTextEdit
} from 'monaco-languageserver-types'
import { registerMarkerDataProvider } from 'monaco-marker-data-provider'
Expand Down Expand Up @@ -311,6 +312,18 @@ export function configureMonacoYaml(monaco: MonacoEditor, options: MonacoYamlOpt
action: { indentAction: monaco.languages.IndentAction.Indent }
}
]
}),

monaco.languages.registerSelectionRangeProvider('yaml', {
async provideSelectionRanges(model, positions) {
const worker = await workerManager.getWorker(model.uri)
const selectionRanges = await worker.getSelectionRanges(
String(model.uri),
positions.map(fromPosition)
)

return selectionRanges?.map(toSelectionRanges)
}
})
]

Expand Down
10 changes: 9 additions & 1 deletion src/yaml.worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
type LocationLink,
type Position,
type Range,
type SelectionRange,
type TextEdit
} from 'vscode-languageserver-types'
import { type Telemetry } from 'yaml-language-server/lib/esm/languageservice/telemetry.js'
Expand Down Expand Up @@ -91,6 +92,11 @@ export interface YAMLWorker {
* Get folding ranges in a YAML document.
*/
getFoldingRanges: (uri: string) => FoldingRange[] | null | undefined

/**
* Get selection ranges in a YAML document
*/
getSelectionRanges: (uri: string, positions: Position[]) => SelectionRange[] | undefined
}

const telemetry: Telemetry = {
Expand Down Expand Up @@ -162,6 +168,8 @@ initialize<YAMLWorker, MonacoYamlOptions>((ctx, { enableSchemaRequest, ...langua

getFoldingRanges: withDocument((document) =>
ls.getFoldingRanges(document, { lineFoldingOnly: true })
)
),

getSelectionRanges: withDocument(ls.getSelectionRanges)
}
})

0 comments on commit 32bb27e

Please sign in to comment.