mirror of
https://github.com/sourcegraph/sourcegraph.git
synced 2026-02-06 17:31:43 +00:00
publish @sourcegraph/extension-api-types package with plain types (#1308)
This is like the vscode-languageserver-types package. It exports types that are useful for *client applications* interacting with Sourcegraph extensions. Sourcegraph extensions DO NOT and SHOULD NOT use this package. Only things like codeintellify (and our internal code) should use it. NOCHANGELOG
This commit is contained in:
parent
3f523a177c
commit
fd374290f2
@ -1,7 +1,7 @@
|
||||
import { TextDocumentDecoration } from '@sourcegraph/extension-api-types'
|
||||
import * as React from 'react'
|
||||
import { render } from 'react-dom'
|
||||
import { ContributableMenu } from '../../../../../shared/src/api/protocol'
|
||||
import { TextDocumentDecoration } from '../../../../../shared/src/api/protocol/plainTypes'
|
||||
import { CommandListPopoverButton } from '../../../../../shared/src/commandPalette/CommandList'
|
||||
import { Notifications } from '../../../../../shared/src/notifications/Notifications'
|
||||
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
import { AdjustmentDirection, DiffPart, PositionAdjuster } from '@sourcegraph/codeintellify'
|
||||
import { Position } from '@sourcegraph/extension-api-types'
|
||||
import { map } from 'rxjs/operators'
|
||||
import { convertSpacesToTabs, spacesToTabsAdjustment } from '.'
|
||||
import { Position } from '../../../../../shared/src/api/protocol/plainTypes'
|
||||
import { FileSpec, RepoSpec, ResolvedRevSpec, RevSpec } from '../../../../../shared/src/util/url'
|
||||
import storage from '../../browser/storage'
|
||||
import { fetchBlobContentLines } from '../../shared/repo/backend'
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
import { TextDocumentDecoration } from '@sourcegraph/extension-api-types'
|
||||
import { Unsubscribable } from 'rxjs'
|
||||
import { TextDocumentDecoration } from '../../../../../shared/src/api/protocol/plainTypes'
|
||||
|
||||
const combineUnsubscribables = (...unsubscribables: Unsubscribable[]): Unsubscribable => ({
|
||||
unsubscribe: () => {
|
||||
|
||||
@ -1,11 +1,11 @@
|
||||
import { DiffPart, JumpURLFetcher } from '@sourcegraph/codeintellify'
|
||||
import { Location } from '@sourcegraph/extension-api-types'
|
||||
import { from, Observable, of, OperatorFunction, throwError } from 'rxjs'
|
||||
import { ajax, AjaxResponse } from 'rxjs/ajax'
|
||||
import { catchError, map, switchMap, tap } from 'rxjs/operators'
|
||||
import { HoverMerged } from '../../../../../shared/src/api/client/types/hover'
|
||||
import { TextDocumentIdentifier } from '../../../../../shared/src/api/client/types/textDocument'
|
||||
import { TextDocumentPositionParams } from '../../../../../shared/src/api/protocol'
|
||||
import { Definition } from '../../../../../shared/src/api/protocol/plainTypes'
|
||||
import { Controller } from '../../../../../shared/src/extensions/controller'
|
||||
import { getModeFromPath } from '../../../../../shared/src/languages'
|
||||
import {
|
||||
@ -182,7 +182,7 @@ const fetchHover = memoizeObservable((pos: AbsoluteRepoFilePosition): Observable
|
||||
return request(url, 'textDocument/hover', body).pipe(extractLSPResponse)
|
||||
}, makeRepoURI)
|
||||
|
||||
const fetchDefinition = memoizeObservable((pos: AbsoluteRepoFilePosition): Observable<Definition> => {
|
||||
const fetchDefinition = memoizeObservable((pos: AbsoluteRepoFilePosition): Observable<Location | Location[] | null> => {
|
||||
const mode = getModeFromPath(pos.filePath)
|
||||
if (!mode || unsupportedModes.has(mode)) {
|
||||
return of([])
|
||||
@ -270,7 +270,7 @@ export function createJumpURLFetcher(
|
||||
|
||||
export interface SimpleProviderFns {
|
||||
fetchHover: (pos: AbsoluteRepoFilePosition) => Observable<HoverMerged | null>
|
||||
fetchDefinition: (pos: AbsoluteRepoFilePosition) => Observable<Definition>
|
||||
fetchDefinition: (pos: AbsoluteRepoFilePosition) => Observable<Location | Location[] | null>
|
||||
}
|
||||
|
||||
export const lspViaAPIXlang: SimpleProviderFns = {
|
||||
@ -299,6 +299,6 @@ export const createLSPFromExtensions = (extensionsController: Controller): Simpl
|
||||
),
|
||||
fetchDefinition: pos =>
|
||||
from(
|
||||
extensionsController.services.textDocumentDefinition.getLocation(toTextDocumentPositionParams(pos))
|
||||
) as Observable<Definition>,
|
||||
extensionsController.services.textDocumentDefinition.getLocations(toTextDocumentPositionParams(pos))
|
||||
) as Observable<Location | Location[] | null>,
|
||||
})
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import { Position, Range } from '../../../../../shared/src/api/protocol/plainTypes'
|
||||
import { Position, Range } from '@sourcegraph/extension-api-types'
|
||||
import { sourcegraphUrl } from '../util/context'
|
||||
import { parseHash } from '../util/url'
|
||||
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import { Position } from '../../../../../shared/src/api/protocol/plainTypes'
|
||||
import { Position } from '@sourcegraph/extension-api-types'
|
||||
import { AbsoluteRepoFile, PositionSpec, ReferencesModeSpec } from '../repo'
|
||||
import { repoUrlCache, sourcegraphUrl } from './context'
|
||||
|
||||
|
||||
@ -182,6 +182,7 @@
|
||||
"@sentry/browser": "^4.4.1",
|
||||
"@slimsag/react-shortcuts": "^1.2.1",
|
||||
"@sourcegraph/codeintellify": "^4.0.0",
|
||||
"@sourcegraph/extension-api-types": "link:packages/@sourcegraph/extension-api-types",
|
||||
"@sourcegraph/react-loading-spinner": "0.0.6",
|
||||
"@sqs/jsonc-parser": "^1.0.3",
|
||||
"@types/he": "1.1.0",
|
||||
|
||||
14
packages/@sourcegraph/extension-api-types/.editorconfig
Normal file
14
packages/@sourcegraph/extension-api-types/.editorconfig
Normal file
@ -0,0 +1,14 @@
|
||||
|
||||
[*]
|
||||
insert_final_newline = true
|
||||
end_of_line = lf
|
||||
charset = utf-8
|
||||
trim_trailing_whitespace = true
|
||||
indent_style = space
|
||||
indent_size = 4
|
||||
|
||||
[*.{json,js,yml}]
|
||||
indent_size = 2
|
||||
|
||||
[*.md]
|
||||
trim_trailing_whitespace = false
|
||||
201
packages/@sourcegraph/extension-api-types/LICENSE
Normal file
201
packages/@sourcegraph/extension-api-types/LICENSE
Normal file
@ -0,0 +1,201 @@
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
APPENDIX: How to apply the Apache License to your work.
|
||||
|
||||
To apply the Apache License to your work, attach the following
|
||||
boilerplate notice, with the fields enclosed by brackets "[]"
|
||||
replaced with your own identifying information. (Don't include
|
||||
the brackets!) The text should be enclosed in the appropriate
|
||||
comment syntax for the file format. We also recommend that a
|
||||
file or class name and description of purpose be included on the
|
||||
same "printed page" as the copyright notice for easier
|
||||
identification within third-party archives.
|
||||
|
||||
Copyright [yyyy] [name of copyright owner]
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
6
packages/@sourcegraph/extension-api-types/README.md
Normal file
6
packages/@sourcegraph/extension-api-types/README.md
Normal file
@ -0,0 +1,6 @@
|
||||
# Sourcegraph extension API types for client applications
|
||||
|
||||
Extensions should use the `sourcegraph` package, not this package. This package is only for client applications
|
||||
that embed Sourcegraph extensions and need to communicate with them.
|
||||
|
||||
See [Sourcegraph extensions documentation](https://docs.sourcegraph.com/extensions) for more information.
|
||||
27
packages/@sourcegraph/extension-api-types/package.json
Normal file
27
packages/@sourcegraph/extension-api-types/package.json
Normal file
@ -0,0 +1,27 @@
|
||||
{
|
||||
"name": "@sourcegraph/extension-api-types",
|
||||
"version": "1.0.1",
|
||||
"description": "Types for working with the Sourcegraph extension API. Extensions should use the 'sourcegraph' package, not this package. This package is only for client applications that embed Sourcegraph extensions and need to communicate with them.",
|
||||
"author": "Sourcegraph",
|
||||
"bugs": {
|
||||
"url": "https://github.com/sourcegraph/sourcegraph/issues"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/sourcegraph/sourcegraph"
|
||||
},
|
||||
"license": "Apache-2.0",
|
||||
"main": "",
|
||||
"types": "src/index.d.ts",
|
||||
"files": [
|
||||
"src"
|
||||
],
|
||||
"sideEffects": false,
|
||||
"scripts": {
|
||||
"tslint": "tslint -c tslint.json -p tsconfig.json './src/**/*.{ts,js}'",
|
||||
"prepublishOnly": "yarn run tslint"
|
||||
},
|
||||
"dependencies": {
|
||||
"sourcegraph": "*"
|
||||
}
|
||||
}
|
||||
12
packages/@sourcegraph/extension-api-types/src/hover.d.ts
vendored
Normal file
12
packages/@sourcegraph/extension-api-types/src/hover.d.ts
vendored
Normal file
@ -0,0 +1,12 @@
|
||||
import * as sourcegraph from 'sourcegraph'
|
||||
import { Range } from './location'
|
||||
|
||||
/**
|
||||
* A hover message.
|
||||
*
|
||||
* @see module:sourcegraph.Hover
|
||||
*/
|
||||
export interface Hover extends Pick<sourcegraph.Hover, 'contents' | '__backcompatContents'> {
|
||||
/** The range that the hover applies to. */
|
||||
readonly range?: Range
|
||||
}
|
||||
4
packages/@sourcegraph/extension-api-types/src/index.d.ts
vendored
Normal file
4
packages/@sourcegraph/extension-api-types/src/index.d.ts
vendored
Normal file
@ -0,0 +1,4 @@
|
||||
export * from './hover'
|
||||
export * from './location'
|
||||
export * from './textDocument'
|
||||
export * from './workspace'
|
||||
66
packages/@sourcegraph/extension-api-types/src/location.d.ts
vendored
Normal file
66
packages/@sourcegraph/extension-api-types/src/location.d.ts
vendored
Normal file
@ -0,0 +1,66 @@
|
||||
/**
|
||||
* A position in a document.
|
||||
*
|
||||
* @see module:sourcegraph.Position
|
||||
*/
|
||||
export interface Position {
|
||||
/** Zero-based line number. */
|
||||
readonly line: number
|
||||
|
||||
/** Zero-based character on a line. */
|
||||
readonly character: number
|
||||
}
|
||||
|
||||
/**
|
||||
* A range represents an ordered pair of two positions. The {@link Range#start} is always before the
|
||||
* {@link Range#end}.
|
||||
*
|
||||
* @see module:sourcegraph.Range
|
||||
*/
|
||||
export interface Range {
|
||||
/**
|
||||
* The start position. It is before or equal to [end](#Range.end).
|
||||
*/
|
||||
readonly start: Position
|
||||
|
||||
/**
|
||||
* The end position. It is after or equal to [start](#Range.start).
|
||||
*/
|
||||
readonly end: Position
|
||||
}
|
||||
|
||||
/**
|
||||
* A selection is a pair of two positions.
|
||||
*
|
||||
* @see module:sourcegraph.Selection
|
||||
*/
|
||||
export interface Selection extends Range {
|
||||
/**
|
||||
* The position at which the selection starts. This position might be before or after {@link Selection#active}.
|
||||
*/
|
||||
readonly anchor: Position
|
||||
|
||||
/**
|
||||
* The position of the cursor. This position might be before or after {@link Selection#anchor}.
|
||||
*/
|
||||
readonly active: Position
|
||||
|
||||
/**
|
||||
* Whether the selection is reversed. The selection is reversed if {@link Selection#active} is before
|
||||
* {@link Selection#anchor}.
|
||||
*/
|
||||
readonly isReversed: boolean
|
||||
}
|
||||
|
||||
/**
|
||||
* A location refers to a document (or a range within a document).
|
||||
*
|
||||
* @see module:sourcegraph.Location
|
||||
*/
|
||||
export interface Location {
|
||||
/** The URI of the document. */
|
||||
readonly uri: string
|
||||
|
||||
/** An optional range within the document. */
|
||||
readonly range?: Range
|
||||
}
|
||||
13
packages/@sourcegraph/extension-api-types/src/textDocument.d.ts
vendored
Normal file
13
packages/@sourcegraph/extension-api-types/src/textDocument.d.ts
vendored
Normal file
@ -0,0 +1,13 @@
|
||||
import * as sourcegraph from 'sourcegraph'
|
||||
import { Range } from './location'
|
||||
|
||||
/**
|
||||
* A decoration to apply to a text document.
|
||||
*
|
||||
* @see module:sourcgraph.TextDocumentDecoration
|
||||
*/
|
||||
export interface TextDocumentDecoration
|
||||
extends Pick<sourcegraph.TextDocumentDecoration, Exclude<keyof sourcegraph.TextDocumentDecoration, 'range'>> {
|
||||
/** The range that the decoration applies to. */
|
||||
range: Range
|
||||
}
|
||||
9
packages/@sourcegraph/extension-api-types/src/workspace.d.ts
vendored
Normal file
9
packages/@sourcegraph/extension-api-types/src/workspace.d.ts
vendored
Normal file
@ -0,0 +1,9 @@
|
||||
/**
|
||||
* A root directory of a workspace.
|
||||
*
|
||||
* @see module:sourcegraph.WorkspaceRoot
|
||||
*/
|
||||
export interface WorkspaceRoot {
|
||||
/** The root URI of the workspace. */
|
||||
readonly uri: string
|
||||
}
|
||||
4
packages/@sourcegraph/extension-api-types/tsconfig.json
Normal file
4
packages/@sourcegraph/extension-api-types/tsconfig.json
Normal file
@ -0,0 +1,4 @@
|
||||
{
|
||||
"extends": "../../../tsconfig.json",
|
||||
"files": ["src/index.d.ts"]
|
||||
}
|
||||
3
packages/@sourcegraph/extension-api-types/tslint.json
Normal file
3
packages/@sourcegraph/extension-api-types/tslint.json
Normal file
@ -0,0 +1,3 @@
|
||||
{
|
||||
"extends": "@sourcegraph/tslint-config"
|
||||
}
|
||||
@ -46,8 +46,10 @@ declare module 'sourcegraph' {
|
||||
export class Position {
|
||||
/** Zero-based line number. */
|
||||
readonly line: number
|
||||
/** Zero-based line number. */
|
||||
|
||||
/** Zero-based character on the line. */
|
||||
readonly character: number
|
||||
|
||||
/**
|
||||
* Constructs a Position from a line and character.
|
||||
*
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
import { TextDocumentDecoration } from '@sourcegraph/extension-api-types'
|
||||
import { BehaviorSubject, Observable, Subscription } from 'rxjs'
|
||||
import { handleRequests } from '../../common/proxy'
|
||||
import { Connection } from '../../protocol/jsonrpc2/connection'
|
||||
import { TextDocumentDecoration } from '../../protocol/plainTypes'
|
||||
import { ProvideTextDocumentDecorationSignature } from '../services/decoration'
|
||||
import { FeatureProviderRegistry } from '../services/registry'
|
||||
import { TextDocumentIdentifier } from '../types/textDocument'
|
||||
|
||||
@ -1,3 +1,4 @@
|
||||
import { Hover, Location } from '@sourcegraph/extension-api-types'
|
||||
import { from, Observable, Subscription } from 'rxjs'
|
||||
import { map } from 'rxjs/operators'
|
||||
import { DocumentSelector } from 'sourcegraph'
|
||||
@ -5,7 +6,6 @@ import { createProxyAndHandleRequests } from '../../common/proxy'
|
||||
import { ExtLanguageFeaturesAPI } from '../../extension/api/languageFeatures'
|
||||
import { ReferenceParams, TextDocumentPositionParams, TextDocumentRegistrationOptions } from '../../protocol'
|
||||
import { Connection } from '../../protocol/jsonrpc2/connection'
|
||||
import { Definition, Hover, Location } from '../../protocol/plainTypes'
|
||||
import { ProvideTextDocumentHoverSignature } from '../services/hover'
|
||||
import {
|
||||
ProvideTextDocumentLocationSignature,
|
||||
@ -83,7 +83,7 @@ export class ClientLanguageFeatures implements ClientLanguageFeaturesAPI {
|
||||
id,
|
||||
this.definitionRegistry.registerProvider(
|
||||
{ documentSelector: selector },
|
||||
(params: TextDocumentPositionParams): Observable<Definition> =>
|
||||
(params: TextDocumentPositionParams): Observable<Location | Location[]> =>
|
||||
from(this.proxy.$observeDefinition(id, params.textDocument.uri, params.position)).pipe(
|
||||
map(result => result || [])
|
||||
)
|
||||
@ -96,7 +96,7 @@ export class ClientLanguageFeatures implements ClientLanguageFeaturesAPI {
|
||||
id,
|
||||
this.typeDefinitionRegistry.registerProvider(
|
||||
{ documentSelector: selector },
|
||||
(params: TextDocumentPositionParams): Observable<Definition> =>
|
||||
(params: TextDocumentPositionParams): Observable<Location | Location[]> =>
|
||||
from(this.proxy.$observeTypeDefinition(id, params.textDocument.uri, params.position)).pipe(
|
||||
map(result => result || [])
|
||||
)
|
||||
@ -109,7 +109,7 @@ export class ClientLanguageFeatures implements ClientLanguageFeaturesAPI {
|
||||
id,
|
||||
this.implementationRegistry.registerProvider(
|
||||
{ documentSelector: selector },
|
||||
(params: TextDocumentPositionParams): Observable<Definition> =>
|
||||
(params: TextDocumentPositionParams): Observable<Location | Location[]> =>
|
||||
from(this.proxy.$observeImplementation(id, params.textDocument.uri, params.position)).pipe(
|
||||
map(result => result || [])
|
||||
)
|
||||
|
||||
@ -1,8 +1,8 @@
|
||||
import { WorkspaceRoot } from '@sourcegraph/extension-api-types'
|
||||
import { Observable, Subscription } from 'rxjs'
|
||||
import { createProxyAndHandleRequests } from '../../common/proxy'
|
||||
import { ExtRootsAPI } from '../../extension/api/roots'
|
||||
import { Connection } from '../../protocol/jsonrpc2/connection'
|
||||
import { WorkspaceRoot } from '../../protocol/plainTypes'
|
||||
|
||||
/** @internal */
|
||||
export class ClientRoots {
|
||||
|
||||
@ -54,7 +54,7 @@ export class ClientViews implements ClientViewsAPI {
|
||||
priority,
|
||||
locationProvider: component
|
||||
? (params: TextDocumentPositionParams) =>
|
||||
this.textDocumentLocations.getLocation(component.locationProvider, params)
|
||||
this.textDocumentLocations.getLocations(component.locationProvider, params)
|
||||
: undefined,
|
||||
} as PanelViewWithComponent)
|
||||
)
|
||||
|
||||
@ -1,8 +1,6 @@
|
||||
import { Selection } from '@sourcegraph/extension-api-types'
|
||||
import assert from 'assert'
|
||||
import { EMPTY_SETTINGS_CASCADE, SettingsCascadeOrError } from '../../../settings/settings'
|
||||
import { Position } from '../../extension/types/position'
|
||||
import { Selection } from '../../extension/types/selection'
|
||||
import * as plain from '../../protocol/plainTypes'
|
||||
import { EMPTY_MODEL, Model } from '../model'
|
||||
import { applyContextUpdate, Context, getComputedContextProperty } from './context'
|
||||
|
||||
@ -43,7 +41,15 @@ describe('getComputedContextProperty', () => {
|
||||
languageId: 'inactive',
|
||||
text: 'inactive',
|
||||
},
|
||||
selections: [new Selection(new Position(11, 22), new Position(33, 44)).toPlain()],
|
||||
selections: [
|
||||
{
|
||||
start: { line: 11, character: 22 },
|
||||
end: { line: 33, character: 44 },
|
||||
anchor: { line: 11, character: 22 },
|
||||
active: { line: 33, character: 44 },
|
||||
isReversed: false,
|
||||
},
|
||||
],
|
||||
isActive: false,
|
||||
},
|
||||
{
|
||||
@ -53,7 +59,15 @@ describe('getComputedContextProperty', () => {
|
||||
languageId: 'l',
|
||||
text: 't',
|
||||
},
|
||||
selections: [new Selection(new Position(1, 2), new Position(3, 4)).toPlain()],
|
||||
selections: [
|
||||
{
|
||||
start: { line: 1, character: 2 },
|
||||
end: { line: 3, character: 4 },
|
||||
anchor: { line: 1, character: 2 },
|
||||
active: { line: 3, character: 4 },
|
||||
isReversed: false,
|
||||
},
|
||||
],
|
||||
isActive: true,
|
||||
},
|
||||
],
|
||||
@ -111,7 +125,7 @@ describe('getComputedContextProperty', () => {
|
||||
null
|
||||
))
|
||||
|
||||
function assertSelection(model: Model, expr: string, expected: plain.Selection): void {
|
||||
function assertSelection(model: Model, expr: string, expected: Selection): void {
|
||||
assert.deepStrictEqual(getComputedContextProperty(model, EMPTY_SETTINGS_CASCADE, {}, expr), expected)
|
||||
assert.deepStrictEqual(
|
||||
getComputedContextProperty(model, EMPTY_SETTINGS_CASCADE, {}, `${expr}.start`),
|
||||
@ -143,6 +157,8 @@ describe('getComputedContextProperty', () => {
|
||||
assertSelection(model, 'component.selection', {
|
||||
start: { line: 1, character: 2 },
|
||||
end: { line: 3, character: 4 },
|
||||
anchor: { line: 1, character: 2 },
|
||||
active: { line: 3, character: 4 },
|
||||
isReversed: false,
|
||||
}))
|
||||
|
||||
@ -153,6 +169,8 @@ describe('getComputedContextProperty', () => {
|
||||
{
|
||||
start: { line: 1, character: 2 },
|
||||
end: { line: 3, character: 4 },
|
||||
anchor: { line: 1, character: 2 },
|
||||
active: { line: 3, character: 4 },
|
||||
isReversed: false,
|
||||
},
|
||||
]
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
import { Selection, WorkspaceRoot } from '@sourcegraph/extension-api-types'
|
||||
import { TextDocumentPositionParams } from '../protocol'
|
||||
import { Selection, WorkspaceRoot } from '../protocol/plainTypes'
|
||||
import { TextDocumentItem } from './types/textDocument'
|
||||
|
||||
/**
|
||||
|
||||
@ -1,8 +1,8 @@
|
||||
import { TextDocumentDecoration } from '@sourcegraph/extension-api-types'
|
||||
import * as assert from 'assert'
|
||||
import { of } from 'rxjs'
|
||||
import { TestScheduler } from 'rxjs/testing'
|
||||
import { TextDocumentIdentifier } from '../../client/types/textDocument'
|
||||
import { TextDocumentDecoration } from '../../protocol/plainTypes'
|
||||
import {
|
||||
decorationAttachmentStyleForTheme,
|
||||
decorationStyleForTheme,
|
||||
|
||||
@ -1,3 +1,4 @@
|
||||
import { TextDocumentDecoration } from '@sourcegraph/extension-api-types'
|
||||
import { combineLatest, Observable } from 'rxjs'
|
||||
import { map, switchMap } from 'rxjs/operators'
|
||||
import {
|
||||
@ -6,7 +7,6 @@ import {
|
||||
ThemableDecorationStyle,
|
||||
} from 'sourcegraph'
|
||||
import { TextDocumentIdentifier } from '../../client/types/textDocument'
|
||||
import { TextDocumentDecoration } from '../../protocol/plainTypes'
|
||||
import { FeatureProviderRegistry } from './registry'
|
||||
import { flattenAndCompact } from './util'
|
||||
|
||||
|
||||
@ -1,8 +1,8 @@
|
||||
import { Hover } from '@sourcegraph/extension-api-types'
|
||||
import { combineLatest, from, Observable } from 'rxjs'
|
||||
import { catchError, defaultIfEmpty, distinctUntilChanged, filter, map, startWith, switchMap } from 'rxjs/operators'
|
||||
import { HoverMerged } from '../../client/types/hover'
|
||||
import { TextDocumentPositionParams } from '../../protocol'
|
||||
import { Hover } from '../../protocol/plainTypes'
|
||||
import { isEqual } from '../../util'
|
||||
import { DocumentFeatureProviderRegistry } from './registry'
|
||||
|
||||
|
||||
@ -1,8 +1,8 @@
|
||||
import { Location } from '@sourcegraph/extension-api-types'
|
||||
import * as assert from 'assert'
|
||||
import { of, throwError } from 'rxjs'
|
||||
import { TestScheduler } from 'rxjs/testing'
|
||||
import { Location } from '../../protocol/plainTypes'
|
||||
import { getLocation, getLocations, ProvideTextDocumentLocationSignature } from './location'
|
||||
import { getLocations, ProvideTextDocumentLocationSignature } from './location'
|
||||
import { FIXTURE } from './registry.test'
|
||||
|
||||
const scheduler = () => new TestScheduler((a, b) => assert.deepStrictEqual(a, b))
|
||||
@ -13,12 +13,12 @@ const FIXTURE_LOCATION: Location = {
|
||||
}
|
||||
const FIXTURE_LOCATIONS: Location | Location[] | null = [FIXTURE_LOCATION, FIXTURE_LOCATION]
|
||||
|
||||
describe('getLocation', () => {
|
||||
describe('getLocations', () => {
|
||||
describe('0 providers', () => {
|
||||
it('returns null', () =>
|
||||
scheduler().run(({ cold, expectObservable }) =>
|
||||
expectObservable(
|
||||
getLocation(
|
||||
getLocations(
|
||||
cold<ProvideTextDocumentLocationSignature[]>('-a-|', { a: [] }),
|
||||
FIXTURE.TextDocumentPositionParams
|
||||
)
|
||||
@ -32,7 +32,7 @@ describe('getLocation', () => {
|
||||
it('returns null result from provider', () =>
|
||||
scheduler().run(({ cold, expectObservable }) =>
|
||||
expectObservable(
|
||||
getLocation(
|
||||
getLocations(
|
||||
cold<ProvideTextDocumentLocationSignature[]>('-a-|', { a: [() => of(null)] }),
|
||||
FIXTURE.TextDocumentPositionParams
|
||||
)
|
||||
@ -44,7 +44,7 @@ describe('getLocation', () => {
|
||||
it('returns result array from provider', () =>
|
||||
scheduler().run(({ cold, expectObservable }) =>
|
||||
expectObservable(
|
||||
getLocation(
|
||||
getLocations(
|
||||
cold<ProvideTextDocumentLocationSignature[]>('-a-|', {
|
||||
a: [() => of(FIXTURE_LOCATIONS)],
|
||||
}),
|
||||
@ -54,27 +54,27 @@ describe('getLocation', () => {
|
||||
a: FIXTURE_LOCATIONS,
|
||||
})
|
||||
))
|
||||
|
||||
it('returns single result from provider', () =>
|
||||
scheduler().run(({ cold, expectObservable }) =>
|
||||
expectObservable(
|
||||
getLocation(
|
||||
cold<ProvideTextDocumentLocationSignature[]>('-a-|', {
|
||||
a: [() => of(FIXTURE_LOCATION)],
|
||||
}),
|
||||
FIXTURE.TextDocumentPositionParams
|
||||
)
|
||||
).toBe('-a-|', {
|
||||
a: FIXTURE_LOCATION,
|
||||
})
|
||||
))
|
||||
})
|
||||
|
||||
it('errors do not propagate', () =>
|
||||
scheduler().run(({ cold, expectObservable }) =>
|
||||
expectObservable(
|
||||
getLocations(
|
||||
cold<ProvideTextDocumentLocationSignature[]>('-a-|', {
|
||||
a: [() => of(FIXTURE_LOCATION), () => throwError('x')],
|
||||
}),
|
||||
FIXTURE.TextDocumentPositionParams
|
||||
)
|
||||
).toBe('-a-|', {
|
||||
a: [FIXTURE_LOCATION],
|
||||
})
|
||||
))
|
||||
|
||||
describe('2 providers', () => {
|
||||
it('returns null result if both providers return null', () =>
|
||||
scheduler().run(({ cold, expectObservable }) =>
|
||||
expectObservable(
|
||||
getLocation(
|
||||
getLocations(
|
||||
cold<ProvideTextDocumentLocationSignature[]>('-a-|', {
|
||||
a: [() => of(null), () => of(null)],
|
||||
}),
|
||||
@ -88,7 +88,7 @@ describe('getLocation', () => {
|
||||
it('omits null result from 1 provider', () =>
|
||||
scheduler().run(({ cold, expectObservable }) =>
|
||||
expectObservable(
|
||||
getLocation(
|
||||
getLocations(
|
||||
cold<ProvideTextDocumentLocationSignature[]>('-a-|', {
|
||||
a: [() => of(FIXTURE_LOCATIONS), () => of(null)],
|
||||
}),
|
||||
@ -102,7 +102,7 @@ describe('getLocation', () => {
|
||||
it('merges results from providers', () =>
|
||||
scheduler().run(({ cold, expectObservable }) =>
|
||||
expectObservable(
|
||||
getLocation(
|
||||
getLocations(
|
||||
cold<ProvideTextDocumentLocationSignature[]>('-a----|', {
|
||||
a: [
|
||||
() =>
|
||||
@ -123,10 +123,12 @@ describe('getLocation', () => {
|
||||
// TODO: We don't actually *want* this "i" emission, but it is tricky to skip it because we
|
||||
// need to use the INITIAL emission from combineLatest to avoid blocking on the slowest
|
||||
// provider.
|
||||
i: {
|
||||
uri: 'file:///f1',
|
||||
range: { start: { line: 1, character: 2 }, end: { line: 3, character: 4 } },
|
||||
},
|
||||
i: [
|
||||
{
|
||||
uri: 'file:///f1',
|
||||
range: { start: { line: 1, character: 2 }, end: { line: 3, character: 4 } },
|
||||
},
|
||||
],
|
||||
a: [
|
||||
{
|
||||
uri: 'file:///f1',
|
||||
@ -145,7 +147,7 @@ describe('getLocation', () => {
|
||||
it('returns stream of results', () =>
|
||||
scheduler().run(({ cold, expectObservable }) =>
|
||||
expectObservable(
|
||||
getLocation(
|
||||
getLocations(
|
||||
cold<ProvideTextDocumentLocationSignature[]>('-a-b-|', {
|
||||
a: [() => of(FIXTURE_LOCATIONS)],
|
||||
b: [() => of(null)],
|
||||
@ -159,47 +161,3 @@ describe('getLocation', () => {
|
||||
))
|
||||
})
|
||||
})
|
||||
|
||||
describe('getLocations', () => {
|
||||
it('wraps single result in array', () =>
|
||||
scheduler().run(({ cold, expectObservable }) =>
|
||||
expectObservable(
|
||||
getLocations(
|
||||
cold<ProvideTextDocumentLocationSignature[]>('-a-|', {
|
||||
a: [() => of(FIXTURE_LOCATION)],
|
||||
}),
|
||||
FIXTURE.TextDocumentPositionParams
|
||||
)
|
||||
).toBe('-a-|', {
|
||||
a: [FIXTURE_LOCATION],
|
||||
})
|
||||
))
|
||||
|
||||
it('errors do not propagate', () =>
|
||||
scheduler().run(({ cold, expectObservable }) =>
|
||||
expectObservable(
|
||||
getLocations(
|
||||
cold<ProvideTextDocumentLocationSignature[]>('-a-|', {
|
||||
a: [() => of(FIXTURE_LOCATION), () => throwError('x')],
|
||||
}),
|
||||
FIXTURE.TextDocumentPositionParams
|
||||
)
|
||||
).toBe('-a-|', {
|
||||
a: [FIXTURE_LOCATION],
|
||||
})
|
||||
))
|
||||
|
||||
it('preserves array results', () =>
|
||||
scheduler().run(({ cold, expectObservable }) =>
|
||||
expectObservable(
|
||||
getLocations(
|
||||
cold<ProvideTextDocumentLocationSignature[]>('-a-|', {
|
||||
a: [() => of(FIXTURE_LOCATIONS)],
|
||||
}),
|
||||
FIXTURE.TextDocumentPositionParams
|
||||
)
|
||||
).toBe('-a-|', {
|
||||
a: FIXTURE_LOCATIONS,
|
||||
})
|
||||
))
|
||||
})
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
import { Location } from '@sourcegraph/extension-api-types'
|
||||
import { combineLatest, from, Observable, of } from 'rxjs'
|
||||
import { catchError, defaultIfEmpty, distinctUntilChanged, filter, map, startWith, switchMap } from 'rxjs/operators'
|
||||
import { ReferenceParams, TextDocumentPositionParams, TextDocumentRegistrationOptions } from '../../protocol'
|
||||
import { Location } from '../../protocol/plainTypes'
|
||||
import { Model, modelToTextDocumentPositionParams } from '../model'
|
||||
import { match, TextDocumentIdentifier } from '../types/textDocument'
|
||||
import { DocumentFeatureProviderRegistry } from './registry'
|
||||
@ -24,8 +24,8 @@ export class TextDocumentLocationProviderRegistry<
|
||||
P extends TextDocumentPositionParams = TextDocumentPositionParams,
|
||||
L extends Location = Location
|
||||
> extends DocumentFeatureProviderRegistry<ProvideTextDocumentLocationSignature<P, L>> {
|
||||
public getLocation(params: P): Observable<L | L[] | null> {
|
||||
return getLocation<P, L>(this.providersForDocument(params.textDocument), params)
|
||||
public getLocations(params: P): Observable<L[] | null> {
|
||||
return getLocations<P, L>(this.providersForDocument(params.textDocument), params)
|
||||
}
|
||||
|
||||
public getLocationsAndProviders(
|
||||
@ -56,30 +56,14 @@ export class TextDocumentLocationProviderRegistry<
|
||||
}
|
||||
}
|
||||
|
||||
const INITIAL = Symbol('INITIAL')
|
||||
|
||||
/**
|
||||
* Returns an observable that emits the providers' location results whenever any of the last-emitted set of
|
||||
* providers emits hovers.
|
||||
*
|
||||
* Most callers should use the TextDocumentLocationProviderRegistry class, which uses the registered providers.
|
||||
*/
|
||||
export function getLocation<
|
||||
P extends TextDocumentPositionParams = TextDocumentPositionParams,
|
||||
L extends Location = Location
|
||||
>(providers: Observable<ProvideTextDocumentLocationSignature<P, L>[]>, params: P): Observable<L | L[] | null> {
|
||||
return getLocations(providers, params).pipe(
|
||||
map(results => {
|
||||
if (results !== null && results.length === 1) {
|
||||
return results[0]
|
||||
}
|
||||
return results
|
||||
})
|
||||
)
|
||||
}
|
||||
|
||||
const INITIAL = Symbol('INITIAL')
|
||||
|
||||
/**
|
||||
* Like getLocation, except the returned observable never emits singular values, always either an array or null.
|
||||
* Most callers should use the TextDocumentLocationProviderRegistry class, which uses the registered providers
|
||||
* (instead of this function, which requires the caller to specify the providers to get locations from).
|
||||
*/
|
||||
export function getLocations<
|
||||
P extends TextDocumentPositionParams = TextDocumentPositionParams,
|
||||
@ -128,7 +112,7 @@ export function getLocations<
|
||||
*/
|
||||
export class TextDocumentReferencesProviderRegistry extends TextDocumentLocationProviderRegistry<ReferenceParams> {
|
||||
/** Gets reference locations from all matching providers. */
|
||||
public getLocation(params: ReferenceParams): Observable<Location[] | null> {
|
||||
public getLocations(params: ReferenceParams): Observable<Location[] | null> {
|
||||
// References are always an array (unlike other locations, which can be returned as L | L[] |
|
||||
// null).
|
||||
return getLocations(this.providersForDocument(params.textDocument), params)
|
||||
@ -174,7 +158,7 @@ export class TextDocumentLocationProviderIDRegistry extends DocumentFeatureProvi
|
||||
*
|
||||
* @param id The provider ID.
|
||||
*/
|
||||
public getLocation(id: string, params: TextDocumentPositionParams): Observable<Location[] | null> {
|
||||
public getLocations(id: string, params: TextDocumentPositionParams): Observable<Location[] | null> {
|
||||
return getLocations(this.providersForDocumentWithID(id, params.textDocument), params)
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,9 +1,9 @@
|
||||
import { Location } from '@sourcegraph/extension-api-types'
|
||||
import React from 'react'
|
||||
import { combineLatest, Observable } from 'rxjs'
|
||||
import { catchError, map, switchMap } from 'rxjs/operators'
|
||||
import * as sourcegraph from 'sourcegraph'
|
||||
import { ContributableViewContainer } from '../../protocol'
|
||||
import * as plain from '../../protocol/plainTypes'
|
||||
import { Entry, FeatureProviderRegistry } from './registry'
|
||||
|
||||
export interface ViewProviderRegistrationOptions {
|
||||
@ -15,7 +15,7 @@ export interface PanelViewWithComponent extends Pick<sourcegraph.PanelView, 'tit
|
||||
/**
|
||||
* The location provider whose results to render in the panel view.
|
||||
*/
|
||||
locationProvider?: Observable<plain.Location[] | null>
|
||||
locationProvider?: Observable<Location[] | null>
|
||||
|
||||
/**
|
||||
* The React element to render in the panel view.
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
import { Hover as PlainHover, Range } from '@sourcegraph/extension-api-types'
|
||||
import { Hover, MarkupContent, MarkupKind } from 'sourcegraph'
|
||||
import { Hover as PlainHover, Range } from '../../protocol/plainTypes'
|
||||
|
||||
/** A hover that is merged from multiple Hover results and normalized. */
|
||||
export interface HoverMerged {
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
import * as clientType from '@sourcegraph/extension-api-types'
|
||||
import * as sourcegraph from 'sourcegraph'
|
||||
import { ClientCodeEditorAPI } from '../../client/api/codeEditor'
|
||||
import * as plain from '../../protocol/plainTypes'
|
||||
import { Range } from '../types/range'
|
||||
import { Selection } from '../types/selection'
|
||||
import { ExtDocuments } from './documents'
|
||||
@ -9,7 +9,7 @@ import { ExtDocuments } from './documents'
|
||||
export class ExtCodeEditor implements sourcegraph.CodeEditor {
|
||||
constructor(
|
||||
private resource: string,
|
||||
public _selections: plain.Selection[],
|
||||
public _selections: clientType.Selection[],
|
||||
public readonly isActive: boolean,
|
||||
private proxy: ClientCodeEditorAPI,
|
||||
private documents: ExtDocuments
|
||||
@ -38,7 +38,7 @@ export class ExtCodeEditor implements sourcegraph.CodeEditor {
|
||||
}
|
||||
}
|
||||
|
||||
function fromTextDocumentDecoration(decoration: sourcegraph.TextDocumentDecoration): plain.TextDocumentDecoration {
|
||||
function fromTextDocumentDecoration(decoration: sourcegraph.TextDocumentDecoration): clientType.TextDocumentDecoration {
|
||||
return {
|
||||
...decoration,
|
||||
range: (decoration.range as Range).toJSON(),
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
import * as clientType from '@sourcegraph/extension-api-types'
|
||||
import { Observable, Unsubscribable } from 'rxjs'
|
||||
import {
|
||||
Definition,
|
||||
DefinitionProvider,
|
||||
DocumentSelector,
|
||||
Hover,
|
||||
@ -14,36 +14,43 @@ import {
|
||||
TypeDefinitionProvider,
|
||||
} from 'sourcegraph'
|
||||
import { ClientLanguageFeaturesAPI } from '../../client/api/languageFeatures'
|
||||
import * as plain from '../../protocol/plainTypes'
|
||||
import { ProviderMap, toProviderResultObservable } from './common'
|
||||
import { ExtDocuments } from './documents'
|
||||
import { fromHover, fromLocation, toPosition } from './types'
|
||||
|
||||
/** @internal */
|
||||
export interface ExtLanguageFeaturesAPI {
|
||||
$observeHover(id: number, resource: string, position: plain.Position): Observable<plain.Hover | null | undefined>
|
||||
$observeDefinition(id: number, resource: string, position: plain.Position): Observable<plain.Definition | undefined>
|
||||
$observeHover(
|
||||
id: number,
|
||||
resource: string,
|
||||
position: clientType.Position
|
||||
): Observable<clientType.Hover | null | undefined>
|
||||
$observeDefinition(
|
||||
id: number,
|
||||
resource: string,
|
||||
position: clientType.Position
|
||||
): Observable<clientType.Location[] | null | undefined>
|
||||
$observeTypeDefinition(
|
||||
id: number,
|
||||
resource: string,
|
||||
position: plain.Position
|
||||
): Observable<plain.Definition | undefined>
|
||||
position: clientType.Position
|
||||
): Observable<clientType.Location[] | null | undefined>
|
||||
$observeImplementation(
|
||||
id: number,
|
||||
resource: string,
|
||||
position: plain.Position
|
||||
): Observable<plain.Definition | undefined>
|
||||
position: clientType.Position
|
||||
): Observable<clientType.Location[] | null | undefined>
|
||||
$observeReferences(
|
||||
id: number,
|
||||
resource: string,
|
||||
position: plain.Position,
|
||||
position: clientType.Position,
|
||||
context: ReferenceContext
|
||||
): Observable<plain.Location[] | null | undefined>
|
||||
): Observable<clientType.Location[] | null | undefined>
|
||||
$observeLocations(
|
||||
id: number,
|
||||
resource: string,
|
||||
position: plain.Position
|
||||
): Observable<plain.Location[] | null | undefined>
|
||||
position: clientType.Position
|
||||
): Observable<clientType.Location[] | null | undefined>
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
@ -62,8 +69,8 @@ export class ExtLanguageFeatures implements ExtLanguageFeaturesAPI, Unsubscribab
|
||||
public $observeHover(
|
||||
id: number,
|
||||
resource: string,
|
||||
position: plain.Position
|
||||
): Observable<plain.Hover | null | undefined> {
|
||||
position: clientType.Position
|
||||
): Observable<clientType.Hover | null | undefined> {
|
||||
const provider = this.registrations.get<HoverProvider>(id)
|
||||
return toProviderResultObservable(
|
||||
this.documents
|
||||
@ -84,15 +91,15 @@ export class ExtLanguageFeatures implements ExtLanguageFeaturesAPI, Unsubscribab
|
||||
public $observeDefinition(
|
||||
id: number,
|
||||
resource: string,
|
||||
position: plain.Position
|
||||
): Observable<plain.Definition | undefined> {
|
||||
position: clientType.Position
|
||||
): Observable<clientType.Location[] | null | undefined> {
|
||||
const provider = this.registrations.get<DefinitionProvider>(id)
|
||||
return toProviderResultObservable(
|
||||
this.documents
|
||||
.getSync(resource)
|
||||
.then<Definition | undefined | Subscribable<Definition | undefined>>(document =>
|
||||
provider.provideDefinition(document, toPosition(position))
|
||||
),
|
||||
.then<
|
||||
Location | Location[] | null | undefined | Subscribable<Location | Location[] | null | undefined>
|
||||
>(document => provider.provideDefinition(document, toPosition(position))),
|
||||
toDefinition
|
||||
)
|
||||
}
|
||||
@ -106,15 +113,15 @@ export class ExtLanguageFeatures implements ExtLanguageFeaturesAPI, Unsubscribab
|
||||
public $observeTypeDefinition(
|
||||
id: number,
|
||||
resource: string,
|
||||
position: plain.Position
|
||||
): Observable<plain.Definition | null | undefined> {
|
||||
position: clientType.Position
|
||||
): Observable<clientType.Location[] | null | undefined> {
|
||||
const provider = this.registrations.get<TypeDefinitionProvider>(id)
|
||||
return toProviderResultObservable(
|
||||
this.documents
|
||||
.getSync(resource)
|
||||
.then<Definition | undefined | Subscribable<Definition | undefined>>(document =>
|
||||
provider.provideTypeDefinition(document, toPosition(position))
|
||||
),
|
||||
.then<
|
||||
Location | Location[] | null | undefined | Subscribable<Location | Location[] | null | undefined>
|
||||
>(document => provider.provideTypeDefinition(document, toPosition(position))),
|
||||
toDefinition
|
||||
)
|
||||
}
|
||||
@ -131,15 +138,15 @@ export class ExtLanguageFeatures implements ExtLanguageFeaturesAPI, Unsubscribab
|
||||
public $observeImplementation(
|
||||
id: number,
|
||||
resource: string,
|
||||
position: plain.Position
|
||||
): Observable<plain.Definition | undefined> {
|
||||
position: clientType.Position
|
||||
): Observable<clientType.Location[] | null | undefined> {
|
||||
const provider = this.registrations.get<ImplementationProvider>(id)
|
||||
return toProviderResultObservable(
|
||||
this.documents
|
||||
.getSync(resource)
|
||||
.then<Definition | undefined | Subscribable<Definition | undefined>>(document =>
|
||||
provider.provideImplementation(document, toPosition(position))
|
||||
),
|
||||
.then<
|
||||
Location | Location[] | null | undefined | Subscribable<Location | Location[] | null | undefined>
|
||||
>(document => provider.provideImplementation(document, toPosition(position))),
|
||||
toDefinition
|
||||
)
|
||||
}
|
||||
@ -156,9 +163,9 @@ export class ExtLanguageFeatures implements ExtLanguageFeaturesAPI, Unsubscribab
|
||||
public $observeReferences(
|
||||
id: number,
|
||||
resource: string,
|
||||
position: plain.Position,
|
||||
position: clientType.Position,
|
||||
context: ReferenceContext
|
||||
): Observable<plain.Location[] | null | undefined> {
|
||||
): Observable<clientType.Location[] | null | undefined> {
|
||||
const provider = this.registrations.get<ReferenceProvider>(id)
|
||||
return toProviderResultObservable(
|
||||
this.documents
|
||||
@ -179,8 +186,8 @@ export class ExtLanguageFeatures implements ExtLanguageFeaturesAPI, Unsubscribab
|
||||
public $observeLocations(
|
||||
id: number,
|
||||
resource: string,
|
||||
position: plain.Position
|
||||
): Observable<plain.Location[] | null | undefined> {
|
||||
position: clientType.Position
|
||||
): Observable<clientType.Location[] | null | undefined> {
|
||||
const provider = this.registrations.get<LocationProvider>(id)
|
||||
return toProviderResultObservable(
|
||||
this.documents
|
||||
@ -212,14 +219,10 @@ export class ExtLanguageFeatures implements ExtLanguageFeaturesAPI, Unsubscribab
|
||||
}
|
||||
}
|
||||
|
||||
function toLocations(result: Location[] | null | undefined): plain.Location[] | null | undefined {
|
||||
function toLocations(result: Location[] | null | undefined): clientType.Location[] | null | undefined {
|
||||
return result ? result.map(location => fromLocation(location)) : result
|
||||
}
|
||||
|
||||
function toDefinition(result: Location[] | Location | null | undefined): plain.Definition | undefined {
|
||||
return result
|
||||
? Array.isArray(result)
|
||||
? result.map(location => fromLocation(location))
|
||||
: fromLocation(result)
|
||||
: result
|
||||
function toDefinition(result: Location[] | Location | null | undefined): clientType.Location[] | null | undefined {
|
||||
return result ? (Array.isArray(result) ? result : [result]).map(location => fromLocation(location)) : result
|
||||
}
|
||||
|
||||
@ -1,11 +1,11 @@
|
||||
import * as clientType from '@sourcegraph/extension-api-types'
|
||||
import { Observable, Subject } from 'rxjs'
|
||||
import * as sourcegraph from 'sourcegraph'
|
||||
import { WorkspaceRoot as PlainWorkspaceRoot } from '../../protocol/plainTypes'
|
||||
import { URI } from '../types/uri'
|
||||
|
||||
/** @internal */
|
||||
export interface ExtRootsAPI {
|
||||
$acceptRoots(roots: PlainWorkspaceRoot[]): void
|
||||
$acceptRoots(roots: clientType.WorkspaceRoot[]): void
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
@ -24,7 +24,7 @@ export class ExtRoots implements ExtRootsAPI {
|
||||
private changes = new Subject<void>()
|
||||
public readonly onDidChange: Observable<void> = this.changes
|
||||
|
||||
public $acceptRoots(roots: PlainWorkspaceRoot[]): void {
|
||||
public $acceptRoots(roots: clientType.WorkspaceRoot[]): void {
|
||||
this.roots = Object.freeze(
|
||||
roots.map(plain => ({ ...plain, uri: new URI(plain.uri) } as sourcegraph.WorkspaceRoot))
|
||||
)
|
||||
|
||||
@ -1,23 +1,23 @@
|
||||
import * as clientType from '@sourcegraph/extension-api-types'
|
||||
import * as sourcegraph from 'sourcegraph'
|
||||
import * as plain from '../../protocol/plainTypes'
|
||||
import { Position } from '../types/position'
|
||||
import { Range } from '../types/range'
|
||||
|
||||
/**
|
||||
* Converts from a plain object {@link plain.Position} to an instance of {@link Position}.
|
||||
* Converts from a plain object {@link clientType.Position} to an instance of {@link Position}.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
export function toPosition(position: plain.Position): Position {
|
||||
export function toPosition(position: clientType.Position): Position {
|
||||
return new Position(position.line, position.character)
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts from an instance of {@link Location} to the plain object {@link plain.Location}.
|
||||
* Converts from an instance of {@link Location} to the plain object {@link clientType.Location}.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
export function fromLocation(location: sourcegraph.Location): plain.Location {
|
||||
export function fromLocation(location: sourcegraph.Location): clientType.Location {
|
||||
return {
|
||||
uri: location.uri.toString(),
|
||||
range: fromRange(location.range),
|
||||
@ -25,11 +25,11 @@ export function fromLocation(location: sourcegraph.Location): plain.Location {
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts from an instance of {@link Hover} to the plain object {@link plain.Hover}.
|
||||
* Converts from an instance of {@link Hover} to the plain object {@link clientType.Hover}.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
export function fromHover(hover: sourcegraph.Hover): plain.Hover {
|
||||
export function fromHover(hover: sourcegraph.Hover): clientType.Hover {
|
||||
return {
|
||||
contents: hover.contents,
|
||||
__backcompatContents: hover.__backcompatContents, // tslint:disable-line deprecation
|
||||
@ -38,11 +38,11 @@ export function fromHover(hover: sourcegraph.Hover): plain.Hover {
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts from an instance of {@link Range} to the plain object {@link plain.Range}.
|
||||
* Converts from an instance of {@link Range} to the plain object {@link clientType.Range}.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
export function fromRange(range: Range | sourcegraph.Range | undefined): plain.Range | undefined {
|
||||
export function fromRange(range: Range | sourcegraph.Range | undefined): clientType.Range | undefined {
|
||||
if (!range) {
|
||||
return undefined
|
||||
}
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
import * as clientType from '@sourcegraph/extension-api-types'
|
||||
import * as sourcegraph from 'sourcegraph'
|
||||
import * as plain from '../../protocol/plainTypes'
|
||||
import { illegalArgument } from './errors'
|
||||
import { Position } from './position'
|
||||
|
||||
@ -142,7 +142,7 @@ export class Range implements sourcegraph.Range {
|
||||
return { start: this._start.toJSON(), end: this._end.toJSON() }
|
||||
}
|
||||
|
||||
public toPlain(): plain.Range {
|
||||
public toPlain(): clientType.Range {
|
||||
return {
|
||||
start: { line: this._start.line, character: this._start.character },
|
||||
end: { line: this._end.line, character: this._end.character },
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
import * as clientType from '@sourcegraph/extension-api-types'
|
||||
import * as sourcegraph from 'sourcegraph'
|
||||
import * as plain from '../../protocol/plainTypes'
|
||||
import { Position } from './position'
|
||||
import { Range } from './range'
|
||||
|
||||
@ -78,14 +78,16 @@ export class Selection extends Range implements sourcegraph.Selection {
|
||||
}
|
||||
}
|
||||
|
||||
public toPlain(): plain.Selection {
|
||||
public toPlain(): clientType.Selection {
|
||||
return {
|
||||
...super.toPlain(),
|
||||
anchor: this.anchor.toJSON(),
|
||||
active: this.active.toJSON(),
|
||||
isReversed: this.isReversed,
|
||||
}
|
||||
}
|
||||
|
||||
public static fromPlain(data: plain.Selection): Selection {
|
||||
public static fromPlain(data: clientType.Selection): Selection {
|
||||
return data.isReversed
|
||||
? new Selection(data.end.line, data.end.character, data.start.line, data.start.character)
|
||||
: new Selection(data.start.line, data.start.character, data.end.line, data.end.character)
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
import * as clientType from '@sourcegraph/extension-api-types'
|
||||
import * as assert from 'assert'
|
||||
import { take } from 'rxjs/operators'
|
||||
import { Range } from '../extension/types/range'
|
||||
import * as plain from '../protocol/plainTypes'
|
||||
import { integrationTestContext } from './helpers.test'
|
||||
|
||||
describe('CodeEditor (integration)', () => {
|
||||
@ -28,7 +28,7 @@ describe('CodeEditor (integration)', () => {
|
||||
range: { start: { line: 1, character: 2 }, end: { line: 3, character: 4 } },
|
||||
backgroundColor: 'red',
|
||||
},
|
||||
] as plain.TextDocumentDecoration[]
|
||||
] as clientType.TextDocumentDecoration[]
|
||||
)
|
||||
|
||||
// Clear the decorations and ensure they are removed.
|
||||
|
||||
@ -1,3 +1,4 @@
|
||||
import { Location } from '@sourcegraph/extension-api-types'
|
||||
import * as assert from 'assert'
|
||||
import { MonoTypeOperatorFunction } from 'rxjs'
|
||||
import { debounceTime, take } from 'rxjs/operators'
|
||||
@ -6,7 +7,6 @@ import { languages as sourcegraphLanguages } from 'sourcegraph'
|
||||
import { Services } from '../client/services'
|
||||
import { assertToJSON } from '../extension/types/common.test'
|
||||
import { URI } from '../extension/types/uri'
|
||||
import { Definition } from '../protocol/plainTypes'
|
||||
import { createBarrier, integrationTestContext } from './helpers.test'
|
||||
|
||||
// HACK: In getLocations and getHover, we need to have all providers first emit INITIAL to avoid having
|
||||
@ -49,7 +49,7 @@ describe('LanguageFeatures (integration)', () => {
|
||||
run => ({ provideDefinition: run } as sourcegraph.DefinitionProvider),
|
||||
services =>
|
||||
services.textDocumentDefinition
|
||||
.getLocation({ textDocument: { uri: 'file:///f' }, position: { line: 1, character: 2 } })
|
||||
.getLocations({ textDocument: { uri: 'file:///f' }, position: { line: 1, character: 2 } })
|
||||
.pipe(
|
||||
WAIT_FOR_RESULT(),
|
||||
take(1)
|
||||
@ -68,7 +68,7 @@ describe('LanguageFeatures (integration)', () => {
|
||||
run => ({ provideTypeDefinition: run } as sourcegraph.TypeDefinitionProvider),
|
||||
services =>
|
||||
services.textDocumentTypeDefinition
|
||||
.getLocation({ textDocument: { uri: 'file:///f' }, position: { line: 1, character: 2 } })
|
||||
.getLocations({ textDocument: { uri: 'file:///f' }, position: { line: 1, character: 2 } })
|
||||
.pipe(
|
||||
WAIT_FOR_RESULT(),
|
||||
take(1)
|
||||
@ -86,7 +86,7 @@ describe('LanguageFeatures (integration)', () => {
|
||||
run => ({ provideImplementation: run } as sourcegraph.ImplementationProvider),
|
||||
services =>
|
||||
services.textDocumentImplementation
|
||||
.getLocation({ textDocument: { uri: 'file:///f' }, position: { line: 1, character: 2 } })
|
||||
.getLocations({ textDocument: { uri: 'file:///f' }, position: { line: 1, character: 2 } })
|
||||
.pipe(
|
||||
WAIT_FOR_RESULT(),
|
||||
take(1)
|
||||
@ -108,7 +108,7 @@ describe('LanguageFeatures (integration)', () => {
|
||||
} as sourcegraph.ReferenceProvider),
|
||||
services =>
|
||||
services.textDocumentReferences
|
||||
.getLocation({
|
||||
.getLocations({
|
||||
textDocument: { uri: 'file:///f' },
|
||||
position: { line: 1, character: 2 },
|
||||
context: { includeDeclaration: true },
|
||||
@ -134,7 +134,7 @@ describe('LanguageFeatures (integration)', () => {
|
||||
} as sourcegraph.LocationProvider),
|
||||
services =>
|
||||
services.textDocumentLocations
|
||||
.getLocation('x', {
|
||||
.getLocations('x', {
|
||||
textDocument: { uri: 'file:///f' },
|
||||
position: { line: 1, character: 2 },
|
||||
})
|
||||
@ -203,7 +203,6 @@ function testLocationProvider<P>(
|
||||
})
|
||||
}
|
||||
|
||||
function labeledDefinitionResults(labels: string[]): Definition {
|
||||
const results = labels.map(label => ({ uri: `file:///${label}`, range: undefined }))
|
||||
return labels.length <= 1 ? results[0] : results
|
||||
function labeledDefinitionResults(labels: string[]): Location | Location[] {
|
||||
return labels.map(label => ({ uri: `file:///${label}`, range: undefined }))
|
||||
}
|
||||
|
||||
@ -1,43 +0,0 @@
|
||||
import * as sourcegraph from 'sourcegraph'
|
||||
|
||||
/** The plain properties of a {@link module:sourcegraph.WorkspaceRoot}, without methods and accessors. */
|
||||
export interface WorkspaceRoot {
|
||||
uri: string
|
||||
}
|
||||
|
||||
/** The plain properties of a {@link module:sourcegraph.Position}, without methods and accessors. */
|
||||
export interface Position extends Pick<sourcegraph.Position, 'line' | 'character'> {
|
||||
line: number
|
||||
character: number
|
||||
}
|
||||
|
||||
/** The plain properties of a {@link module:sourcegraph.Range}, without methods and accessors. */
|
||||
export interface Range {
|
||||
start: Position
|
||||
end: Position
|
||||
}
|
||||
|
||||
/** The plain properties of a {@link module:sourcegraph.Selection}, without methods and accessors. */
|
||||
export interface Selection extends Range {
|
||||
isReversed: boolean
|
||||
}
|
||||
|
||||
/** The plain properties of a {@link module:sourcegraph.Location}, without methods and accessors. */
|
||||
export interface Location {
|
||||
uri: string
|
||||
range?: Range
|
||||
}
|
||||
|
||||
/** The plain properties of a {@link module:sourcegraph.Definition}, without methods and accessors. */
|
||||
export type Definition = Location | Location[] | null
|
||||
|
||||
/** The plain properties of a {@link module:sourcegraph.Hover}, without methods and accessors. */
|
||||
export interface Hover extends Pick<sourcegraph.Hover, 'contents' | '__backcompatContents'> {
|
||||
range?: Range
|
||||
}
|
||||
|
||||
/** The plain properties of a {@link module:sourcegraph.TextDocumentDecoration}, without methods and accessors. */
|
||||
export interface TextDocumentDecoration
|
||||
extends Pick<sourcegraph.TextDocumentDecoration, Exclude<keyof sourcegraph.TextDocumentDecoration, 'range'>> {
|
||||
range: Range
|
||||
}
|
||||
@ -1,6 +1,6 @@
|
||||
import { Position } from '@sourcegraph/extension-api-types'
|
||||
import { DocumentSelector } from 'sourcegraph'
|
||||
import { TextDocumentIdentifier } from '../client/types/textDocument'
|
||||
import { Position } from './plainTypes'
|
||||
|
||||
/**
|
||||
* A parameter literal used in requests to pass a text document and a position inside that
|
||||
|
||||
@ -1,10 +1,10 @@
|
||||
import { Position } from '@sourcegraph/extension-api-types'
|
||||
import { isArray } from 'lodash-es'
|
||||
import { concat, from, of, Subscription, Unsubscribable } from 'rxjs'
|
||||
import { first } from 'rxjs/operators'
|
||||
import { Services } from '../api/client/services'
|
||||
import { KeyPath, SettingsEdit } from '../api/client/services/settings'
|
||||
import { ActionContributionClientCommandUpdateConfiguration } from '../api/protocol'
|
||||
import { Position } from '../api/protocol/plainTypes'
|
||||
import { PlatformContext } from '../platform/context'
|
||||
|
||||
/**
|
||||
@ -54,7 +54,7 @@ export function registerBuiltinClientCommands(
|
||||
command: 'executeLocationProvider',
|
||||
run: (id: string, uri: string, position: Position) =>
|
||||
concat(
|
||||
textDocumentLocations.getLocation(id, { textDocument: { uri }, position }),
|
||||
textDocumentLocations.getLocations(id, { textDocument: { uri }, position }),
|
||||
// Concat with [] to avoid undefined promise value when the getLocation observable completes
|
||||
// without emitting. See https://github.com/ReactiveX/rxjs/issues/1736.
|
||||
of([])
|
||||
|
||||
@ -1,3 +1,4 @@
|
||||
import { Location } from '@sourcegraph/extension-api-types'
|
||||
import { LoadingSpinner } from '@sourcegraph/react-loading-spinner'
|
||||
import { upperFirst } from 'lodash'
|
||||
import AlertCircleIcon from 'mdi-react/AlertCircleIcon'
|
||||
@ -5,7 +6,6 @@ import MapSearchIcon from 'mdi-react/MapSearchIcon'
|
||||
import * as React from 'react'
|
||||
import { Observable, Subject, Subscription } from 'rxjs'
|
||||
import { catchError, distinctUntilChanged, map, startWith, switchMap } from 'rxjs/operators'
|
||||
import { Location } from '../../api/protocol/plainTypes'
|
||||
import { FetchFileCtx } from '../../components/CodeExcerpt'
|
||||
import { FileMatch, IFileMatch, ILineMatch } from '../../components/FileMatch'
|
||||
import { VirtualList } from '../../components/VirtualList'
|
||||
|
||||
@ -1,8 +1,8 @@
|
||||
import { Location } from '@sourcegraph/extension-api-types'
|
||||
import { LoadingSpinner } from '@sourcegraph/react-loading-spinner'
|
||||
import * as React from 'react'
|
||||
import { Observable, of, Subject, Subscription } from 'rxjs'
|
||||
import { catchError, distinctUntilChanged, endWith, map, startWith, switchMap, tap } from 'rxjs/operators'
|
||||
import { Location } from '../../api/protocol/plainTypes'
|
||||
import { FetchFileCtx } from '../../components/CodeExcerpt'
|
||||
import { RepositoryIcon } from '../../components/icons' // TODO: Switch to mdi icon
|
||||
import { RepoLink } from '../../components/RepoLink'
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import { Location } from '../../api/protocol/plainTypes'
|
||||
import { Location } from '@sourcegraph/extension-api-types'
|
||||
|
||||
/**
|
||||
* Grouped locations returned by {@link groupLocations}.
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import { Position, Range } from '../api/protocol/plainTypes'
|
||||
import { Position, Range } from '@sourcegraph/extension-api-types'
|
||||
|
||||
export interface RepoSpec {
|
||||
/**
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
import { HoverMerged } from '@sourcegraph/codeintellify/lib/types'
|
||||
import { Location, TextDocumentDecoration } from '@sourcegraph/extension-api-types'
|
||||
import { Observable } from 'rxjs'
|
||||
import { map } from 'rxjs/operators'
|
||||
import { Definition, Location, TextDocumentDecoration } from '../../../shared/src/api/protocol/plainTypes'
|
||||
import { ExtensionsControllerProps } from '../../../shared/src/extensions/controller'
|
||||
import { AbsoluteRepoFile, parseRepoURI, toPrettyBlobURL } from '../../../shared/src/util/url'
|
||||
import { toAbsoluteBlobURL } from '../util/url'
|
||||
@ -47,8 +47,8 @@ export function getHover(
|
||||
export function getDefinition(
|
||||
ctx: LSPTextDocumentPositionParams,
|
||||
{ extensionsController }: ExtensionsControllerProps
|
||||
): Observable<Definition> {
|
||||
return extensionsController.services.textDocumentDefinition.getLocation({
|
||||
): Observable<Location[] | null> {
|
||||
return extensionsController.services.textDocumentDefinition.getLocations({
|
||||
textDocument: { uri: `git://${ctx.repoPath}?${ctx.commitID}#${ctx.filePath}` },
|
||||
position: {
|
||||
character: ctx.position.character - 1,
|
||||
@ -71,12 +71,11 @@ export function getJumpURL(
|
||||
extensions: ExtensionsControllerProps
|
||||
): Observable<string | null> {
|
||||
return getDefinition(ctx, extensions).pipe(
|
||||
map(def => {
|
||||
const defArray = Array.isArray(def) ? def : [def]
|
||||
def = defArray[0]
|
||||
if (!def) {
|
||||
map(defs => {
|
||||
if (!defs || defs.length === 0) {
|
||||
return null
|
||||
}
|
||||
const def = defs[0]
|
||||
|
||||
const uri = parseRepoURI(def.uri) as LSPTextDocumentPositionParams
|
||||
if (def.range) {
|
||||
@ -92,19 +91,6 @@ export function getJumpURL(
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Wrap the value in an array. Unlike Lodash's castArray, it maps null to [] (not [null]).
|
||||
*/
|
||||
function castArray<T>(value: null | T | T[]): T[] {
|
||||
if (value === null) {
|
||||
return []
|
||||
}
|
||||
if (!Array.isArray(value)) {
|
||||
return [value]
|
||||
}
|
||||
return value
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetches references (in the same repository) to the symbol at the given location.
|
||||
*
|
||||
@ -114,19 +100,17 @@ function castArray<T>(value: null | T | T[]): T[] {
|
||||
export function getReferences(
|
||||
ctx: LSPTextDocumentPositionParams & { includeDeclaration?: boolean },
|
||||
{ extensionsController }: ExtensionsControllerProps
|
||||
): Observable<Location[]> {
|
||||
return extensionsController.services.textDocumentReferences
|
||||
.getLocation({
|
||||
textDocument: { uri: `git://${ctx.repoPath}?${ctx.commitID}#${ctx.filePath}` },
|
||||
position: {
|
||||
character: ctx.position.character - 1,
|
||||
line: ctx.position.line - 1,
|
||||
},
|
||||
context: {
|
||||
includeDeclaration: ctx.includeDeclaration !== false, // undefined means true
|
||||
},
|
||||
})
|
||||
.pipe(map(castArray))
|
||||
): Observable<Location[] | null> {
|
||||
return extensionsController.services.textDocumentReferences.getLocations({
|
||||
textDocument: { uri: `git://${ctx.repoPath}?${ctx.commitID}#${ctx.filePath}` },
|
||||
position: {
|
||||
character: ctx.position.character - 1,
|
||||
line: ctx.position.line - 1,
|
||||
},
|
||||
context: {
|
||||
includeDeclaration: ctx.includeDeclaration !== false, // undefined means true
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
@ -138,16 +122,14 @@ export function getReferences(
|
||||
export function getImplementations(
|
||||
ctx: LSPTextDocumentPositionParams,
|
||||
{ extensionsController }: ExtensionsControllerProps
|
||||
): Observable<Location[]> {
|
||||
return extensionsController.services.textDocumentImplementation
|
||||
.getLocation({
|
||||
textDocument: { uri: `git://${ctx.repoPath}?${ctx.commitID}#${ctx.filePath}` },
|
||||
position: {
|
||||
character: ctx.position.character - 1,
|
||||
line: ctx.position.line - 1,
|
||||
},
|
||||
})
|
||||
.pipe(map(castArray))
|
||||
): Observable<Location[] | null> {
|
||||
return extensionsController.services.textDocumentImplementation.getLocations({
|
||||
textDocument: { uri: `git://${ctx.repoPath}?${ctx.commitID}#${ctx.filePath}` },
|
||||
position: {
|
||||
character: ctx.position.character - 1,
|
||||
line: ctx.position.line - 1,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -1,3 +1,4 @@
|
||||
import { WorkspaceRoot } from '@sourcegraph/extension-api-types'
|
||||
import AlertCircleIcon from 'mdi-react/AlertCircleIcon'
|
||||
import MapSearchIcon from 'mdi-react/MapSearchIcon'
|
||||
import * as React from 'react'
|
||||
@ -5,7 +6,6 @@ import { Route, RouteComponentProps, Switch } from 'react-router'
|
||||
import { merge, Subject, Subscription } from 'rxjs'
|
||||
import { catchError, distinctUntilChanged, map, switchMap, tap, withLatestFrom } from 'rxjs/operators'
|
||||
import { redirectToExternalHost } from '.'
|
||||
import { WorkspaceRoot } from '../../../shared/src/api/protocol/plainTypes'
|
||||
import { ExtensionsControllerProps } from '../../../shared/src/extensions/controller'
|
||||
import * as GQL from '../../../shared/src/graphql/schema'
|
||||
import { PlatformContextProps } from '../../../shared/src/platform/context'
|
||||
|
||||
@ -1,10 +1,10 @@
|
||||
import { Position, Range } from '@sourcegraph/extension-api-types'
|
||||
import { upperFirst } from 'lodash'
|
||||
import ExportIcon from 'mdi-react/ExportIcon'
|
||||
import GithubCircleIcon from 'mdi-react/GithubCircleIcon'
|
||||
import * as React from 'react'
|
||||
import { merge, of, Subject, Subscription } from 'rxjs'
|
||||
import { catchError, distinctUntilChanged, map, startWith, switchMap } from 'rxjs/operators'
|
||||
import { Position, Range } from '../../../../shared/src/api/protocol/plainTypes'
|
||||
import { PhabricatorIcon } from '../../../../shared/src/components/icons' // TODO: Switch mdi icon
|
||||
import * as GQL from '../../../../shared/src/graphql/schema'
|
||||
import { asError, ErrorLike, isErrorLike } from '../../../../shared/src/util/errors'
|
||||
|
||||
@ -6,6 +6,7 @@ import {
|
||||
HoverState,
|
||||
} from '@sourcegraph/codeintellify'
|
||||
import { getCodeElementsInRange, locateTarget } from '@sourcegraph/codeintellify/lib/token_position'
|
||||
import { TextDocumentDecoration } from '@sourcegraph/extension-api-types'
|
||||
import * as H from 'history'
|
||||
import { isEqual, pick } from 'lodash'
|
||||
import * as React from 'react'
|
||||
@ -13,7 +14,6 @@ import { Link, LinkProps } from 'react-router-dom'
|
||||
import { combineLatest, fromEvent, merge, Observable, Subject, Subscription } from 'rxjs'
|
||||
import { catchError, distinctUntilChanged, filter, map, share, switchMap, withLatestFrom } from 'rxjs/operators'
|
||||
import { decorationStyleForTheme } from '../../../../shared/src/api/client/services/decoration'
|
||||
import { TextDocumentDecoration } from '../../../../shared/src/api/protocol/plainTypes'
|
||||
import { ExtensionsControllerProps } from '../../../../shared/src/extensions/controller'
|
||||
import { PlatformContextProps } from '../../../../shared/src/platform/context'
|
||||
import { SettingsCascadeProps } from '../../../../shared/src/settings/settings'
|
||||
|
||||
@ -6,12 +6,12 @@ import {
|
||||
HoverState,
|
||||
} from '@sourcegraph/codeintellify'
|
||||
import { getTokenAtPosition } from '@sourcegraph/codeintellify/lib/token_position'
|
||||
import { Position } from '@sourcegraph/extension-api-types'
|
||||
import * as H from 'history'
|
||||
import * as React from 'react'
|
||||
import { Link, LinkProps } from 'react-router-dom'
|
||||
import { Subject, Subscription } from 'rxjs'
|
||||
import { catchError, filter, map, withLatestFrom } from 'rxjs/operators'
|
||||
import { Position } from '../../../../shared/src/api/protocol/plainTypes'
|
||||
import { ExtensionsControllerProps } from '../../../../shared/src/extensions/controller'
|
||||
import * as GQL from '../../../../shared/src/graphql/schema'
|
||||
import { getModeFromPath } from '../../../../shared/src/languages'
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import { Position, Range, Selection } from '../../../shared/src/api/protocol/plainTypes'
|
||||
import { Position, Range, Selection } from '@sourcegraph/extension-api-types'
|
||||
import {
|
||||
AbsoluteRepoFile,
|
||||
encodeRepoRev,
|
||||
@ -157,10 +157,14 @@ export function lprToSelectionsZeroIndexed(lpr: LineOrPositionOrRange): Selectio
|
||||
if (range === undefined) {
|
||||
return []
|
||||
}
|
||||
const start: Position = { line: range.start.line - 1, character: range.start.character - 1 }
|
||||
const end: Position = { line: range.end.line - 1, character: range.end.character - 1 }
|
||||
return [
|
||||
{
|
||||
start: { line: range.start.line - 1, character: range.start.character - 1 },
|
||||
end: { line: range.end.line - 1, character: range.end.character - 1 },
|
||||
start,
|
||||
end,
|
||||
anchor: start,
|
||||
active: end,
|
||||
isReversed: false,
|
||||
},
|
||||
]
|
||||
|
||||
@ -1147,6 +1147,10 @@
|
||||
rxjs "^6.3.2"
|
||||
vscode-languageserver-types "^3.8.2"
|
||||
|
||||
"@sourcegraph/extension-api-types@link:packages/@sourcegraph/extension-api-types":
|
||||
version "0.0.0"
|
||||
uid ""
|
||||
|
||||
"@sourcegraph/prettierrc@^2.2.0":
|
||||
version "2.2.0"
|
||||
resolved "https://registry.npmjs.org/@sourcegraph/prettierrc/-/prettierrc-2.2.0.tgz#af4a6fcd465b0a39a07ffbd8f2d3414d01e603e8"
|
||||
@ -13371,6 +13375,11 @@ source-map@^0.7.2:
|
||||
resolved "https://registry.npmjs.org/source-map/-/source-map-0.7.3.tgz#5302f8169031735226544092e64981f751750383"
|
||||
integrity sha512-CkCj6giN3S+n9qrYiBTX5gystlENnRW5jZeNLHpe6aue+SrHcG5VYwujhW9s4dY31mEGsxBDrHR6oI69fTXsaQ==
|
||||
|
||||
sourcegraph@*:
|
||||
version "19.4.0"
|
||||
resolved "https://registry.npmjs.org/sourcegraph/-/sourcegraph-19.4.0.tgz#5e02146ef06a5a3b0e37d1f09375bbfa011ddee8"
|
||||
integrity sha512-fyx0nFtySTdn+Y1JR7LPdl2lj9vHCbSgoLjzMEW5iuBjVuVHXdVldq3kjBYoI98MI6L53qATT993sDVrq4Jqwg==
|
||||
|
||||
"sourcegraph@link:packages/sourcegraph-extension-api":
|
||||
version "0.0.0"
|
||||
uid ""
|
||||
|
||||
Loading…
Reference in New Issue
Block a user