mirror of
https://github.com/danbulant/monaco-yaml
synced 2026-07-06 19:40:55 +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,
|
editor,
|
||||||
IDisposable,
|
IDisposable,
|
||||||
IMarkdownString,
|
IMarkdownString,
|
||||||
IRange,
|
|
||||||
languages,
|
languages,
|
||||||
MarkerSeverity,
|
MarkerSeverity,
|
||||||
Position,
|
Position,
|
||||||
|
|
@ -152,18 +151,6 @@ function fromPosition(position: Position): ls.Position {
|
||||||
return { character: position.column - 1, line: position.lineNumber - 1 };
|
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 {
|
function toRange(range: ls.Range): Range {
|
||||||
if (!range) {
|
if (!range) {
|
||||||
return;
|
return;
|
||||||
|
|
@ -445,7 +432,7 @@ export class DocumentFormattingEditProvider implements languages.DocumentFormatt
|
||||||
const resource = model.uri;
|
const resource = model.uri;
|
||||||
|
|
||||||
return this._worker(resource).then((worker) =>
|
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) {
|
if (!edits || edits.length === 0) {
|
||||||
return;
|
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,
|
languageId,
|
||||||
new languageFeatures.DocumentFormattingEditProvider(worker),
|
new languageFeatures.DocumentFormattingEditProvider(worker),
|
||||||
),
|
),
|
||||||
languages.registerDocumentRangeFormattingEditProvider(
|
|
||||||
languageId,
|
|
||||||
new languageFeatures.DocumentRangeFormattingEditProvider(worker),
|
|
||||||
),
|
|
||||||
new languageFeatures.DiagnosticsAdapter(languageId, worker, defaults),
|
new languageFeatures.DiagnosticsAdapter(languageId, worker, defaults),
|
||||||
languages.setLanguageConfiguration(languageId, richEditConfiguration),
|
languages.setLanguageConfiguration(languageId, richEditConfiguration),
|
||||||
);
|
);
|
||||||
|
|
|
||||||
|
|
@ -57,11 +57,7 @@ export class YAMLWorker {
|
||||||
return this._languageService.doHover(document, position);
|
return this._languageService.doHover(document, position);
|
||||||
}
|
}
|
||||||
|
|
||||||
format(
|
format(uri: string, options: yamlService.CustomFormatterOptions): PromiseLike<ls.TextEdit[]> {
|
||||||
uri: string,
|
|
||||||
range: ls.Range,
|
|
||||||
options: yamlService.CustomFormatterOptions,
|
|
||||||
): PromiseLike<ls.TextEdit[]> {
|
|
||||||
const document = this._getTextDocument(uri);
|
const document = this._getTextDocument(uri);
|
||||||
const textEdits = this._languageService.doFormat(document, options);
|
const textEdits = this._languageService.doFormat(document, options);
|
||||||
return Promise.resolve(textEdits);
|
return Promise.resolve(textEdits);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue