From fd374290f2ea5c6b57619490907609f448bbbfb0 Mon Sep 17 00:00:00 2001 From: Quinn Slack Date: Sun, 9 Dec 2018 21:35:40 -0800 Subject: [PATCH] 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 --- .../src/libs/code_intelligence/extensions.tsx | 2 +- .../src/libs/phabricator/code_intelligence.ts | 2 +- .../browser/src/shared/backend/extensions.ts | 2 +- client/browser/src/shared/backend/lsp.tsx | 10 +- client/browser/src/shared/repo/index.tsx | 2 +- client/browser/src/shared/util/url.tsx | 2 +- package.json | 1 + .../extension-api-types/.editorconfig | 14 ++ .../@sourcegraph/extension-api-types/LICENSE | 201 ++++++++++++++++++ .../extension-api-types/README.md | 6 + .../extension-api-types/package.json | 27 +++ .../extension-api-types/src/hover.d.ts | 12 ++ .../extension-api-types/src/index.d.ts | 4 + .../extension-api-types/src/location.d.ts | 66 ++++++ .../extension-api-types/src/textDocument.d.ts | 13 ++ .../extension-api-types/src/workspace.d.ts | 9 + .../extension-api-types/tsconfig.json | 4 + .../extension-api-types/tslint.json | 3 + .../src/sourcegraph.d.ts | 4 +- shared/src/api/client/api/codeEditor.ts | 2 +- shared/src/api/client/api/languageFeatures.ts | 8 +- shared/src/api/client/api/roots.ts | 2 +- shared/src/api/client/api/views.ts | 2 +- shared/src/api/client/context/context.test.ts | 30 ++- shared/src/api/client/model.ts | 2 +- .../api/client/services/decoration.test.ts | 2 +- shared/src/api/client/services/decoration.ts | 2 +- shared/src/api/client/services/hover.ts | 2 +- .../src/api/client/services/location.test.ts | 102 +++------ shared/src/api/client/services/location.ts | 34 +-- shared/src/api/client/services/view.ts | 4 +- shared/src/api/client/types/hover.ts | 2 +- shared/src/api/extension/api/codeEditor.ts | 6 +- .../src/api/extension/api/languageFeatures.ts | 83 ++++---- shared/src/api/extension/api/roots.ts | 6 +- shared/src/api/extension/api/types.ts | 18 +- shared/src/api/extension/types/range.ts | 4 +- shared/src/api/extension/types/selection.ts | 8 +- .../api/integration-test/codeEditor.test.ts | 4 +- .../integration-test/languageFeatures.test.ts | 17 +- shared/src/api/protocol/plainTypes.ts | 43 ---- shared/src/api/protocol/textDocument.ts | 2 +- shared/src/commands/commands.ts | 4 +- shared/src/panel/views/FileLocations.tsx | 2 +- .../panel/views/HierarchicalLocationsView.tsx | 2 +- shared/src/panel/views/locations.ts | 2 +- shared/src/util/url.ts | 2 +- web/src/backend/features.ts | 68 +++--- web/src/repo/RepoContainer.tsx | 2 +- web/src/repo/actions/GoToCodeHostAction.tsx | 2 +- web/src/repo/blob/Blob.tsx | 2 +- web/src/search/input/CodeIntellifyBlob.tsx | 2 +- web/src/util/url.ts | 10 +- yarn.lock | 9 + 54 files changed, 577 insertions(+), 299 deletions(-) create mode 100644 packages/@sourcegraph/extension-api-types/.editorconfig create mode 100644 packages/@sourcegraph/extension-api-types/LICENSE create mode 100644 packages/@sourcegraph/extension-api-types/README.md create mode 100644 packages/@sourcegraph/extension-api-types/package.json create mode 100644 packages/@sourcegraph/extension-api-types/src/hover.d.ts create mode 100644 packages/@sourcegraph/extension-api-types/src/index.d.ts create mode 100644 packages/@sourcegraph/extension-api-types/src/location.d.ts create mode 100644 packages/@sourcegraph/extension-api-types/src/textDocument.d.ts create mode 100644 packages/@sourcegraph/extension-api-types/src/workspace.d.ts create mode 100644 packages/@sourcegraph/extension-api-types/tsconfig.json create mode 100644 packages/@sourcegraph/extension-api-types/tslint.json delete mode 100644 shared/src/api/protocol/plainTypes.ts diff --git a/client/browser/src/libs/code_intelligence/extensions.tsx b/client/browser/src/libs/code_intelligence/extensions.tsx index f4eae9ccf1e..c5fa507125e 100644 --- a/client/browser/src/libs/code_intelligence/extensions.tsx +++ b/client/browser/src/libs/code_intelligence/extensions.tsx @@ -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' diff --git a/client/browser/src/libs/phabricator/code_intelligence.ts b/client/browser/src/libs/phabricator/code_intelligence.ts index 6afef803d33..96d914f1777 100644 --- a/client/browser/src/libs/phabricator/code_intelligence.ts +++ b/client/browser/src/libs/phabricator/code_intelligence.ts @@ -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' diff --git a/client/browser/src/shared/backend/extensions.ts b/client/browser/src/shared/backend/extensions.ts index 37611f81abb..3e99402a17e 100644 --- a/client/browser/src/shared/backend/extensions.ts +++ b/client/browser/src/shared/backend/extensions.ts @@ -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: () => { diff --git a/client/browser/src/shared/backend/lsp.tsx b/client/browser/src/shared/backend/lsp.tsx index 5940cc82bd8..4aad7fd8ba1 100644 --- a/client/browser/src/shared/backend/lsp.tsx +++ b/client/browser/src/shared/backend/lsp.tsx @@ -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 => { +const fetchDefinition = memoizeObservable((pos: AbsoluteRepoFilePosition): Observable => { 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 - fetchDefinition: (pos: AbsoluteRepoFilePosition) => Observable + fetchDefinition: (pos: AbsoluteRepoFilePosition) => Observable } 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, + extensionsController.services.textDocumentDefinition.getLocations(toTextDocumentPositionParams(pos)) + ) as Observable, }) diff --git a/client/browser/src/shared/repo/index.tsx b/client/browser/src/shared/repo/index.tsx index 116cbd063a7..3a20cbfe2ed 100644 --- a/client/browser/src/shared/repo/index.tsx +++ b/client/browser/src/shared/repo/index.tsx @@ -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' diff --git a/client/browser/src/shared/util/url.tsx b/client/browser/src/shared/util/url.tsx index 4d9a3f4994e..71d9fa19a5c 100644 --- a/client/browser/src/shared/util/url.tsx +++ b/client/browser/src/shared/util/url.tsx @@ -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' diff --git a/package.json b/package.json index 4d0ad2e005c..7ac383ca14c 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/packages/@sourcegraph/extension-api-types/.editorconfig b/packages/@sourcegraph/extension-api-types/.editorconfig new file mode 100644 index 00000000000..537fe37c1e0 --- /dev/null +++ b/packages/@sourcegraph/extension-api-types/.editorconfig @@ -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 \ No newline at end of file diff --git a/packages/@sourcegraph/extension-api-types/LICENSE b/packages/@sourcegraph/extension-api-types/LICENSE new file mode 100644 index 00000000000..f49a4e16e68 --- /dev/null +++ b/packages/@sourcegraph/extension-api-types/LICENSE @@ -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. \ No newline at end of file diff --git a/packages/@sourcegraph/extension-api-types/README.md b/packages/@sourcegraph/extension-api-types/README.md new file mode 100644 index 00000000000..d8b11e4d066 --- /dev/null +++ b/packages/@sourcegraph/extension-api-types/README.md @@ -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. diff --git a/packages/@sourcegraph/extension-api-types/package.json b/packages/@sourcegraph/extension-api-types/package.json new file mode 100644 index 00000000000..d8935a32ec4 --- /dev/null +++ b/packages/@sourcegraph/extension-api-types/package.json @@ -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": "*" + } +} diff --git a/packages/@sourcegraph/extension-api-types/src/hover.d.ts b/packages/@sourcegraph/extension-api-types/src/hover.d.ts new file mode 100644 index 00000000000..bebb0d473f0 --- /dev/null +++ b/packages/@sourcegraph/extension-api-types/src/hover.d.ts @@ -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 { + /** The range that the hover applies to. */ + readonly range?: Range +} diff --git a/packages/@sourcegraph/extension-api-types/src/index.d.ts b/packages/@sourcegraph/extension-api-types/src/index.d.ts new file mode 100644 index 00000000000..46f1fa305a9 --- /dev/null +++ b/packages/@sourcegraph/extension-api-types/src/index.d.ts @@ -0,0 +1,4 @@ +export * from './hover' +export * from './location' +export * from './textDocument' +export * from './workspace' diff --git a/packages/@sourcegraph/extension-api-types/src/location.d.ts b/packages/@sourcegraph/extension-api-types/src/location.d.ts new file mode 100644 index 00000000000..a516f730c1b --- /dev/null +++ b/packages/@sourcegraph/extension-api-types/src/location.d.ts @@ -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 +} diff --git a/packages/@sourcegraph/extension-api-types/src/textDocument.d.ts b/packages/@sourcegraph/extension-api-types/src/textDocument.d.ts new file mode 100644 index 00000000000..fc2a62268c0 --- /dev/null +++ b/packages/@sourcegraph/extension-api-types/src/textDocument.d.ts @@ -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> { + /** The range that the decoration applies to. */ + range: Range +} diff --git a/packages/@sourcegraph/extension-api-types/src/workspace.d.ts b/packages/@sourcegraph/extension-api-types/src/workspace.d.ts new file mode 100644 index 00000000000..fa71531c9d1 --- /dev/null +++ b/packages/@sourcegraph/extension-api-types/src/workspace.d.ts @@ -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 +} diff --git a/packages/@sourcegraph/extension-api-types/tsconfig.json b/packages/@sourcegraph/extension-api-types/tsconfig.json new file mode 100644 index 00000000000..8e117d0366b --- /dev/null +++ b/packages/@sourcegraph/extension-api-types/tsconfig.json @@ -0,0 +1,4 @@ +{ + "extends": "../../../tsconfig.json", + "files": ["src/index.d.ts"] +} diff --git a/packages/@sourcegraph/extension-api-types/tslint.json b/packages/@sourcegraph/extension-api-types/tslint.json new file mode 100644 index 00000000000..e9465680e7b --- /dev/null +++ b/packages/@sourcegraph/extension-api-types/tslint.json @@ -0,0 +1,3 @@ +{ + "extends": "@sourcegraph/tslint-config" +} diff --git a/packages/sourcegraph-extension-api/src/sourcegraph.d.ts b/packages/sourcegraph-extension-api/src/sourcegraph.d.ts index fe21dce9f5e..5a4febb4a87 100644 --- a/packages/sourcegraph-extension-api/src/sourcegraph.d.ts +++ b/packages/sourcegraph-extension-api/src/sourcegraph.d.ts @@ -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. * diff --git a/shared/src/api/client/api/codeEditor.ts b/shared/src/api/client/api/codeEditor.ts index cf0781ae30a..941e3aef03f 100644 --- a/shared/src/api/client/api/codeEditor.ts +++ b/shared/src/api/client/api/codeEditor.ts @@ -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' diff --git a/shared/src/api/client/api/languageFeatures.ts b/shared/src/api/client/api/languageFeatures.ts index 3e6c3ab208a..42d284970ff 100644 --- a/shared/src/api/client/api/languageFeatures.ts +++ b/shared/src/api/client/api/languageFeatures.ts @@ -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 => + (params: TextDocumentPositionParams): Observable => 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 => + (params: TextDocumentPositionParams): Observable => 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 => + (params: TextDocumentPositionParams): Observable => from(this.proxy.$observeImplementation(id, params.textDocument.uri, params.position)).pipe( map(result => result || []) ) diff --git a/shared/src/api/client/api/roots.ts b/shared/src/api/client/api/roots.ts index 4b847ef1b6c..5d50b56824d 100644 --- a/shared/src/api/client/api/roots.ts +++ b/shared/src/api/client/api/roots.ts @@ -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 { diff --git a/shared/src/api/client/api/views.ts b/shared/src/api/client/api/views.ts index 78fd289a834..582a1eb6ad4 100644 --- a/shared/src/api/client/api/views.ts +++ b/shared/src/api/client/api/views.ts @@ -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) ) diff --git a/shared/src/api/client/context/context.test.ts b/shared/src/api/client/context/context.test.ts index 07d1b470fe5..e1203527f60 100644 --- a/shared/src/api/client/context/context.test.ts +++ b/shared/src/api/client/context/context.test.ts @@ -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, }, ] diff --git a/shared/src/api/client/model.ts b/shared/src/api/client/model.ts index c622d60f2d9..22ff2df85fb 100644 --- a/shared/src/api/client/model.ts +++ b/shared/src/api/client/model.ts @@ -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' /** diff --git a/shared/src/api/client/services/decoration.test.ts b/shared/src/api/client/services/decoration.test.ts index e296d47b482..849bd587170 100644 --- a/shared/src/api/client/services/decoration.test.ts +++ b/shared/src/api/client/services/decoration.test.ts @@ -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, diff --git a/shared/src/api/client/services/decoration.ts b/shared/src/api/client/services/decoration.ts index 394eb9eda97..56f15d5e169 100644 --- a/shared/src/api/client/services/decoration.ts +++ b/shared/src/api/client/services/decoration.ts @@ -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' diff --git a/shared/src/api/client/services/hover.ts b/shared/src/api/client/services/hover.ts index b9fd2c63169..552041151c7 100644 --- a/shared/src/api/client/services/hover.ts +++ b/shared/src/api/client/services/hover.ts @@ -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' diff --git a/shared/src/api/client/services/location.test.ts b/shared/src/api/client/services/location.test.ts index b88b68042ee..213a2353a01 100644 --- a/shared/src/api/client/services/location.test.ts +++ b/shared/src/api/client/services/location.test.ts @@ -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('-a-|', { a: [] }), FIXTURE.TextDocumentPositionParams ) @@ -32,7 +32,7 @@ describe('getLocation', () => { it('returns null result from provider', () => scheduler().run(({ cold, expectObservable }) => expectObservable( - getLocation( + getLocations( cold('-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('-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('-a-|', { - a: [() => of(FIXTURE_LOCATION)], - }), - FIXTURE.TextDocumentPositionParams - ) - ).toBe('-a-|', { - a: FIXTURE_LOCATION, - }) - )) }) + it('errors do not propagate', () => + scheduler().run(({ cold, expectObservable }) => + expectObservable( + getLocations( + cold('-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('-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('-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('-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('-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('-a-|', { - a: [() => of(FIXTURE_LOCATION)], - }), - FIXTURE.TextDocumentPositionParams - ) - ).toBe('-a-|', { - a: [FIXTURE_LOCATION], - }) - )) - - it('errors do not propagate', () => - scheduler().run(({ cold, expectObservable }) => - expectObservable( - getLocations( - cold('-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('-a-|', { - a: [() => of(FIXTURE_LOCATIONS)], - }), - FIXTURE.TextDocumentPositionParams - ) - ).toBe('-a-|', { - a: FIXTURE_LOCATIONS, - }) - )) -}) diff --git a/shared/src/api/client/services/location.ts b/shared/src/api/client/services/location.ts index 5138dbfe238..97529ed89d7 100644 --- a/shared/src/api/client/services/location.ts +++ b/shared/src/api/client/services/location.ts @@ -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> { - public getLocation(params: P): Observable { - return getLocation(this.providersForDocument(params.textDocument), params) + public getLocations(params: P): Observable { + return getLocations(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[]>, params: P): Observable { - 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 { /** Gets reference locations from all matching providers. */ - public getLocation(params: ReferenceParams): Observable { + public getLocations(params: ReferenceParams): Observable { // 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 { + public getLocations(id: string, params: TextDocumentPositionParams): Observable { return getLocations(this.providersForDocumentWithID(id, params.textDocument), params) } } diff --git a/shared/src/api/client/services/view.ts b/shared/src/api/client/services/view.ts index bca6579b579..6de35ae515e 100644 --- a/shared/src/api/client/services/view.ts +++ b/shared/src/api/client/services/view.ts @@ -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 + locationProvider?: Observable /** * The React element to render in the panel view. diff --git a/shared/src/api/client/types/hover.ts b/shared/src/api/client/types/hover.ts index 4b373a8cce6..c1b9fda8d89 100644 --- a/shared/src/api/client/types/hover.ts +++ b/shared/src/api/client/types/hover.ts @@ -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 { diff --git a/shared/src/api/extension/api/codeEditor.ts b/shared/src/api/extension/api/codeEditor.ts index f5050bc05cc..4a66c2816e2 100644 --- a/shared/src/api/extension/api/codeEditor.ts +++ b/shared/src/api/extension/api/codeEditor.ts @@ -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(), diff --git a/shared/src/api/extension/api/languageFeatures.ts b/shared/src/api/extension/api/languageFeatures.ts index 34838f9edb9..70c5f9b4182 100644 --- a/shared/src/api/extension/api/languageFeatures.ts +++ b/shared/src/api/extension/api/languageFeatures.ts @@ -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 - $observeDefinition(id: number, resource: string, position: plain.Position): Observable + $observeHover( + id: number, + resource: string, + position: clientType.Position + ): Observable + $observeDefinition( + id: number, + resource: string, + position: clientType.Position + ): Observable $observeTypeDefinition( id: number, resource: string, - position: plain.Position - ): Observable + position: clientType.Position + ): Observable $observeImplementation( id: number, resource: string, - position: plain.Position - ): Observable + position: clientType.Position + ): Observable $observeReferences( id: number, resource: string, - position: plain.Position, + position: clientType.Position, context: ReferenceContext - ): Observable + ): Observable $observeLocations( id: number, resource: string, - position: plain.Position - ): Observable + position: clientType.Position + ): Observable } /** @internal */ @@ -62,8 +69,8 @@ export class ExtLanguageFeatures implements ExtLanguageFeaturesAPI, Unsubscribab public $observeHover( id: number, resource: string, - position: plain.Position - ): Observable { + position: clientType.Position + ): Observable { const provider = this.registrations.get(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 { + position: clientType.Position + ): Observable { const provider = this.registrations.get(id) return toProviderResultObservable( this.documents .getSync(resource) - .then>(document => - provider.provideDefinition(document, toPosition(position)) - ), + .then< + Location | Location[] | null | undefined | Subscribable + >(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 { + position: clientType.Position + ): Observable { const provider = this.registrations.get(id) return toProviderResultObservable( this.documents .getSync(resource) - .then>(document => - provider.provideTypeDefinition(document, toPosition(position)) - ), + .then< + Location | Location[] | null | undefined | Subscribable + >(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 { + position: clientType.Position + ): Observable { const provider = this.registrations.get(id) return toProviderResultObservable( this.documents .getSync(resource) - .then>(document => - provider.provideImplementation(document, toPosition(position)) - ), + .then< + Location | Location[] | null | undefined | Subscribable + >(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 { + ): Observable { const provider = this.registrations.get(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 { + position: clientType.Position + ): Observable { const provider = this.registrations.get(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 } diff --git a/shared/src/api/extension/api/roots.ts b/shared/src/api/extension/api/roots.ts index 4c30b798619..db501bc2092 100644 --- a/shared/src/api/extension/api/roots.ts +++ b/shared/src/api/extension/api/roots.ts @@ -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() public readonly onDidChange: Observable = 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)) ) diff --git a/shared/src/api/extension/api/types.ts b/shared/src/api/extension/api/types.ts index f415e8489e5..3464d25fb5f 100644 --- a/shared/src/api/extension/api/types.ts +++ b/shared/src/api/extension/api/types.ts @@ -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 } diff --git a/shared/src/api/extension/types/range.ts b/shared/src/api/extension/types/range.ts index 35a277a70df..697ec6f01ba 100644 --- a/shared/src/api/extension/types/range.ts +++ b/shared/src/api/extension/types/range.ts @@ -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 }, diff --git a/shared/src/api/extension/types/selection.ts b/shared/src/api/extension/types/selection.ts index 481e250842b..54ea92fd78a 100644 --- a/shared/src/api/extension/types/selection.ts +++ b/shared/src/api/extension/types/selection.ts @@ -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) diff --git a/shared/src/api/integration-test/codeEditor.test.ts b/shared/src/api/integration-test/codeEditor.test.ts index e87bb102897..8f4da093d04 100644 --- a/shared/src/api/integration-test/codeEditor.test.ts +++ b/shared/src/api/integration-test/codeEditor.test.ts @@ -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. diff --git a/shared/src/api/integration-test/languageFeatures.test.ts b/shared/src/api/integration-test/languageFeatures.test.ts index 61c2ae9544e..ba80179c8f8 100644 --- a/shared/src/api/integration-test/languageFeatures.test.ts +++ b/shared/src/api/integration-test/languageFeatures.test.ts @@ -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

( }) } -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 })) } diff --git a/shared/src/api/protocol/plainTypes.ts b/shared/src/api/protocol/plainTypes.ts deleted file mode 100644 index fa496efe17f..00000000000 --- a/shared/src/api/protocol/plainTypes.ts +++ /dev/null @@ -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 { - 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 { - range?: Range -} - -/** The plain properties of a {@link module:sourcegraph.TextDocumentDecoration}, without methods and accessors. */ -export interface TextDocumentDecoration - extends Pick> { - range: Range -} diff --git a/shared/src/api/protocol/textDocument.ts b/shared/src/api/protocol/textDocument.ts index 3174eb1f2ae..ef4ca9c60e8 100644 --- a/shared/src/api/protocol/textDocument.ts +++ b/shared/src/api/protocol/textDocument.ts @@ -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 diff --git a/shared/src/commands/commands.ts b/shared/src/commands/commands.ts index 91e0ff97aa0..f0a1287f8b6 100644 --- a/shared/src/commands/commands.ts +++ b/shared/src/commands/commands.ts @@ -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([]) diff --git a/shared/src/panel/views/FileLocations.tsx b/shared/src/panel/views/FileLocations.tsx index 0a2182dc1b4..1a30089dbb0 100644 --- a/shared/src/panel/views/FileLocations.tsx +++ b/shared/src/panel/views/FileLocations.tsx @@ -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' diff --git a/shared/src/panel/views/HierarchicalLocationsView.tsx b/shared/src/panel/views/HierarchicalLocationsView.tsx index 208e319302a..fdbe5c6046a 100644 --- a/shared/src/panel/views/HierarchicalLocationsView.tsx +++ b/shared/src/panel/views/HierarchicalLocationsView.tsx @@ -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' diff --git a/shared/src/panel/views/locations.ts b/shared/src/panel/views/locations.ts index 7fd27c0c482..1c451504da0 100644 --- a/shared/src/panel/views/locations.ts +++ b/shared/src/panel/views/locations.ts @@ -1,4 +1,4 @@ -import { Location } from '../../api/protocol/plainTypes' +import { Location } from '@sourcegraph/extension-api-types' /** * Grouped locations returned by {@link groupLocations}. diff --git a/shared/src/util/url.ts b/shared/src/util/url.ts index 29d94da3bb4..9fb3bf78d7a 100644 --- a/shared/src/util/url.ts +++ b/shared/src/util/url.ts @@ -1,4 +1,4 @@ -import { Position, Range } from '../api/protocol/plainTypes' +import { Position, Range } from '@sourcegraph/extension-api-types' export interface RepoSpec { /** diff --git a/web/src/backend/features.ts b/web/src/backend/features.ts index 39b2177c66f..61020d00c35 100644 --- a/web/src/backend/features.ts +++ b/web/src/backend/features.ts @@ -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 { - return extensionsController.services.textDocumentDefinition.getLocation({ +): Observable { + 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 { 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(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(value: null | T | T[]): T[] { export function getReferences( ctx: LSPTextDocumentPositionParams & { includeDeclaration?: boolean }, { extensionsController }: ExtensionsControllerProps -): Observable { - 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 { + 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 { - 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 { + 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, + }, + }) } /** diff --git a/web/src/repo/RepoContainer.tsx b/web/src/repo/RepoContainer.tsx index 21456c9bb30..b42bd8e16f1 100644 --- a/web/src/repo/RepoContainer.tsx +++ b/web/src/repo/RepoContainer.tsx @@ -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' diff --git a/web/src/repo/actions/GoToCodeHostAction.tsx b/web/src/repo/actions/GoToCodeHostAction.tsx index 6477df4ab8f..c9c9d721f95 100644 --- a/web/src/repo/actions/GoToCodeHostAction.tsx +++ b/web/src/repo/actions/GoToCodeHostAction.tsx @@ -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' diff --git a/web/src/repo/blob/Blob.tsx b/web/src/repo/blob/Blob.tsx index 8d7f60e6c38..2cef0efe238 100644 --- a/web/src/repo/blob/Blob.tsx +++ b/web/src/repo/blob/Blob.tsx @@ -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' diff --git a/web/src/search/input/CodeIntellifyBlob.tsx b/web/src/search/input/CodeIntellifyBlob.tsx index 8395e0d59b8..672c87a62cd 100644 --- a/web/src/search/input/CodeIntellifyBlob.tsx +++ b/web/src/search/input/CodeIntellifyBlob.tsx @@ -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' diff --git a/web/src/util/url.ts b/web/src/util/url.ts index 07a5fe2fa77..1c4b3b456fd 100644 --- a/web/src/util/url.ts +++ b/web/src/util/url.ts @@ -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, }, ] diff --git a/yarn.lock b/yarn.lock index 5c06c84733f..7a871ddd512 100644 --- a/yarn.lock +++ b/yarn.lock @@ -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 ""