-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
plugin: add
LinkedEditingRanges
support
The commit adds support for the `LinkedEditingRanges` VS Code API including the provider, and registering the provider with `registerLinkedEditingRangeProvider`. Signed-off-by: vince-fugnitto <[email protected]>
- Loading branch information
1 parent
cd33db1
commit a122fd8
Showing
9 changed files
with
235 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// ***************************************************************************** | ||
// Copyright (C) 2022 Ericsson and others. | ||
// | ||
// This program and the accompanying materials are made available under the | ||
// terms of the Eclipse Public License v. 2.0 which is available at | ||
// http://www.eclipse.org/legal/epl-2.0. | ||
// | ||
// This Source Code may also be made available under the following Secondary | ||
// Licenses when the conditions for such availability set forth in the Eclipse | ||
// Public License v. 2.0 are satisfied: GNU General Public License, version 2 | ||
// with the GNU Classpath Exception which is available at | ||
// https://www.gnu.org/software/classpath/license.html. | ||
// | ||
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 | ||
// ***************************************************************************** | ||
|
||
import * as theia from '@theia/plugin'; | ||
import { SerializedIndentationRule, SerializedOnEnterRule, SerializedRegExp } from '../common'; | ||
|
||
export function serializeEnterRules(rules?: theia.OnEnterRule[]): SerializedOnEnterRule[] | undefined { | ||
if (typeof rules === 'undefined' || rules === null) { | ||
return undefined; | ||
} | ||
|
||
return rules.map(r => | ||
({ | ||
action: r.action, | ||
beforeText: serializeRegExp(r.beforeText), | ||
afterText: serializeRegExp(r.afterText) | ||
} as SerializedOnEnterRule)); | ||
} | ||
|
||
export function serializeRegExp(regexp?: RegExp): SerializedRegExp | undefined { | ||
if (typeof regexp === 'undefined' || regexp === null) { | ||
return undefined; | ||
} | ||
|
||
return { | ||
pattern: regexp.source, | ||
flags: (regexp.global ? 'g' : '') + (regexp.ignoreCase ? 'i' : '') + (regexp.multiline ? 'm' : '') | ||
}; | ||
} | ||
|
||
export function serializeIndentation(indentationRules?: theia.IndentationRule): SerializedIndentationRule | undefined { | ||
if (typeof indentationRules === 'undefined' || indentationRules === null) { | ||
return undefined; | ||
} | ||
|
||
return { | ||
increaseIndentPattern: serializeRegExp(indentationRules.increaseIndentPattern), | ||
decreaseIndentPattern: serializeRegExp(indentationRules.decreaseIndentPattern), | ||
indentNextLinePattern: serializeRegExp(indentationRules.indentNextLinePattern), | ||
unIndentedLinePattern: serializeRegExp(indentationRules.unIndentedLinePattern) | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
packages/plugin-ext/src/plugin/languages/linked-editing-range.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// ***************************************************************************** | ||
// Copyright (C) 2022 Ericsson and others. | ||
// | ||
// This program and the accompanying materials are made available under the | ||
// terms of the Eclipse Public License v. 2.0 which is available at | ||
// http://www.eclipse.org/legal/epl-2.0. | ||
// | ||
// This Source Code may also be made available under the following Secondary | ||
// Licenses when the conditions for such availability set forth in the Eclipse | ||
// Public License v. 2.0 are satisfied: GNU General Public License, version 2 | ||
// with the GNU Classpath Exception which is available at | ||
// https://www.gnu.org/software/classpath/license.html. | ||
// | ||
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 | ||
// ***************************************************************************** | ||
|
||
import * as theia from '@theia/plugin'; | ||
import * as rpc from '../../common/plugin-api-rpc'; | ||
import { DocumentsExtImpl } from '../documents'; | ||
import { LinkedEditingRanges } from '../../common/plugin-api-rpc-model'; | ||
import { URI } from '@theia/core/shared/vscode-uri'; | ||
import { coalesce } from '../../common/arrays'; | ||
import { fromRange, toPosition } from '../type-converters'; | ||
import { serializeRegExp } from '../languages-utils'; | ||
|
||
export class LinkedEditingRangeAdapter { | ||
|
||
constructor( | ||
private readonly documents: DocumentsExtImpl, | ||
private readonly provider: theia.LinkedEditingRangeProvider | ||
) { } | ||
|
||
async provideRanges(resource: URI, position: rpc.Position, token: theia.CancellationToken): Promise<LinkedEditingRanges | undefined> { | ||
|
||
const doc = this.documents.getDocument(resource); | ||
const pos = toPosition(position); | ||
|
||
const value = await this.provider.provideLinkedEditingRanges(doc, pos, token); | ||
if (value && Array.isArray(value.ranges)) { | ||
return { | ||
ranges: coalesce(value.ranges.map(r => fromRange(r))), | ||
wordPattern: serializeRegExp(value.wordPattern) | ||
}; | ||
} | ||
return undefined; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.