mirror of
https://github.com/danbulant/monaco-yaml
synced 2026-06-19 22:41:39 +00:00
Merge pull request #77 from remcohaszing/remove-document-range-formatting-edit-provider
Remove DocumentRangeFormattingEditProvider
This commit is contained in:
commit
d7e5aa7744
3 changed files with 2 additions and 47 deletions
|
|
@ -2,7 +2,6 @@ import {
|
|||
editor,
|
||||
IDisposable,
|
||||
IMarkdownString,
|
||||
IRange,
|
||||
languages,
|
||||
MarkerSeverity,
|
||||
Position,
|
||||
|
|
@ -152,18 +151,6 @@ function fromPosition(position: Position): ls.Position {
|
|||
return { character: position.column - 1, line: position.lineNumber - 1 };
|
||||
}
|
||||
|
||||
function fromRange(range: IRange): ls.Range {
|
||||
if (!range) {
|
||||
return;
|
||||
}
|
||||
return {
|
||||
start: {
|
||||
line: range.startLineNumber - 1,
|
||||
character: range.startColumn - 1,
|
||||
},
|
||||
end: { line: range.endLineNumber - 1, character: range.endColumn - 1 },
|
||||
};
|
||||
}
|
||||
function toRange(range: ls.Range): Range {
|
||||
if (!range) {
|
||||
return;
|
||||
|
|
@ -445,7 +432,7 @@ export class DocumentFormattingEditProvider implements languages.DocumentFormatt
|
|||
const resource = model.uri;
|
||||
|
||||
return this._worker(resource).then((worker) =>
|
||||
worker.format(String(resource), null, fromFormattingOptions(options)).then((edits) => {
|
||||
worker.format(String(resource), fromFormattingOptions(options)).then((edits) => {
|
||||
if (!edits || edits.length === 0) {
|
||||
return;
|
||||
}
|
||||
|
|
@ -454,27 +441,3 @@ export class DocumentFormattingEditProvider implements languages.DocumentFormatt
|
|||
);
|
||||
}
|
||||
}
|
||||
|
||||
export class DocumentRangeFormattingEditProvider
|
||||
implements languages.DocumentRangeFormattingEditProvider {
|
||||
constructor(private _worker: WorkerAccessor) {}
|
||||
|
||||
provideDocumentRangeFormattingEdits(
|
||||
model: editor.IReadOnlyModel,
|
||||
range: Range,
|
||||
options: languages.FormattingOptions,
|
||||
): PromiseLike<editor.ISingleEditOperation[]> {
|
||||
const resource = model.uri;
|
||||
|
||||
return this._worker(resource).then((worker) =>
|
||||
worker
|
||||
.format(String(resource), fromRange(range), fromFormattingOptions(options))
|
||||
.then((edits) => {
|
||||
if (!edits || edits.length === 0) {
|
||||
return;
|
||||
}
|
||||
return edits.map(toTextEdit);
|
||||
}),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -62,10 +62,6 @@ export function setupMode(defaults: LanguageServiceDefaultsImpl): void {
|
|||
languageId,
|
||||
new languageFeatures.DocumentFormattingEditProvider(worker),
|
||||
),
|
||||
languages.registerDocumentRangeFormattingEditProvider(
|
||||
languageId,
|
||||
new languageFeatures.DocumentRangeFormattingEditProvider(worker),
|
||||
),
|
||||
new languageFeatures.DiagnosticsAdapter(languageId, worker, defaults),
|
||||
languages.setLanguageConfiguration(languageId, richEditConfiguration),
|
||||
);
|
||||
|
|
|
|||
|
|
@ -57,11 +57,7 @@ export class YAMLWorker {
|
|||
return this._languageService.doHover(document, position);
|
||||
}
|
||||
|
||||
format(
|
||||
uri: string,
|
||||
range: ls.Range,
|
||||
options: yamlService.CustomFormatterOptions,
|
||||
): PromiseLike<ls.TextEdit[]> {
|
||||
format(uri: string, options: yamlService.CustomFormatterOptions): PromiseLike<ls.TextEdit[]> {
|
||||
const document = this._getTextDocument(uri);
|
||||
const textEdits = this._languageService.doFormat(document, options);
|
||||
return Promise.resolve(textEdits);
|
||||
|
|
|
|||
Loading…
Reference in a new issue