forked from eclipse-theia/theia
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implementation of SelectionRange and SelectionRangeProvider API
Signed-off-by: Vladyslav Zhukovskyi <vzhukovs@redhat.com>
- Loading branch information
Showing
9 changed files
with
195 additions
and
0 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
79 changes: 79 additions & 0 deletions
79
packages/plugin-ext/src/plugin/languages/selection-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,79 @@ | ||
/******************************************************************************** | ||
* Copyright (C) 2020 Red Hat, Inc. 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 | ||
********************************************************************************/ | ||
/*--------------------------------------------------------------------------------------------- | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
* Licensed under the MIT License. See License.txt in the project root for license information. | ||
*--------------------------------------------------------------------------------------------*/ | ||
|
||
// copied and modified from https://github.com/microsoft/vscode/blob/standalone/0.19.x/src/vs/workbench/api/common/extHostLanguageFeatures.ts#L1107-L1151 | ||
|
||
import * as theia from '@theia/plugin'; | ||
import { DocumentsExtImpl } from '../documents'; | ||
import { URI } from 'vscode-uri/lib/umd'; | ||
import * as model from '../../common/plugin-api-rpc-model'; | ||
import * as Converter from '../type-converters'; | ||
import * as types from '../types-impl'; | ||
|
||
export class SelectionRangeProviderAdapter { | ||
|
||
constructor( | ||
private readonly provider: theia.SelectionRangeProvider, | ||
private readonly documents: DocumentsExtImpl | ||
) { } | ||
|
||
provideSelectionRanges(resource: URI, position: monaco.IPosition[], token: theia.CancellationToken): Promise<model.SelectionRange[][]> { | ||
const documentData = this.documents.getDocumentData(resource); | ||
|
||
if (!documentData) { | ||
return Promise.reject(new Error(`There are no document for ${resource}`)); | ||
} | ||
|
||
const document = documentData.document; | ||
const positions = position.map(pos => Converter.toPosition(pos)); | ||
|
||
return Promise.resolve(this.provider.provideSelectionRanges(document, positions, token)).then(allProviderRanges => { | ||
if (!Array.isArray(allProviderRanges) || allProviderRanges.length === 0) { | ||
return []; | ||
} | ||
|
||
if (allProviderRanges.length !== positions.length) { | ||
return []; | ||
} | ||
|
||
const allResults: model.SelectionRange[][] = []; | ||
for (let i = 0; i < positions.length; i++) { | ||
const oneResult: model.SelectionRange[] = []; | ||
allResults.push(oneResult); | ||
|
||
let last: types.Position | theia.Range = positions[i]; | ||
let selectionRange = allProviderRanges[i]; | ||
|
||
while (true) { | ||
if (!selectionRange.range.contains(last)) { | ||
return Promise.reject('INVALID selection range, must contain the previous range'); | ||
} | ||
oneResult.push(Converter.fromSelectionRange(selectionRange)); | ||
if (!selectionRange.parent) { | ||
break; | ||
} | ||
last = selectionRange.range; | ||
selectionRange = selectionRange.parent; | ||
} | ||
} | ||
return allResults; | ||
}); | ||
} | ||
} |
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