Skip to content

Commit

Permalink
sourcegraph: Remove noop extension controler (#45926)
Browse files Browse the repository at this point in the history
Commit: a0facbe1e0a883b3341e2fb98e21aaf69ae3b46e
  • Loading branch information
Philipp Spiess authored and sourcegraph-bot committed Dec 23, 2022
1 parent 3544e4a commit af119ef
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 157 deletions.
90 changes: 0 additions & 90 deletions sourcegraph/client/shared/src/codeintel/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,12 @@ import {
TextDocumentIdentifier,
TextDocumentPositionParameters,
} from '@sourcegraph/client-api'
import { MaybeLoadingResult } from '@sourcegraph/codeintellify'
// eslint-disable-next-line no-restricted-imports
import { isDefined } from '@sourcegraph/common/src/types'
import * as clientType from '@sourcegraph/extension-api-types'

import { match } from '../api/client/types/textDocument'
import { FlatExtensionHostAPI } from '../api/contract'
import { proxySubscribable } from '../api/extension/api/common'
import { toPosition } from '../api/extension/api/types'
import { PanelViewData } from '../api/extension/extensionHostApi'
import { getModeFromPath } from '../languages'
import type { PlatformContext } from '../platform/context'
import { isSettingsValid, Settings, SettingsCascade } from '../settings/settings'
Expand Down Expand Up @@ -199,89 +195,3 @@ function newSettingsGetter(settingsCascade: SettingsCascade<Settings>): sourcegr
return <T>(setting: string): T | undefined =>
settingsCascade.final && (settingsCascade.final[setting] as T | undefined)
}

// Replaces codeintel functions from the "old" extension/webworker extension API
// with new implementations of code that lives in this repository. The old
// implementation invoked codeintel functions via webworkers, and the codeintel
// implementation lived in a separate repository
// https://github.com/sourcegraph/code-intel-extensions Ideally, we should
// update all the usages of `comlink.Remote<FlatExtensionHostAPI>` with the new
// `CodeIntelAPI` interfaces, but that would require refactoring a lot of files.
// To minimize the risk of breaking changes caused by the deprecation of
// extensions, we monkey patch the old implementation with new implementations.
// The benefit of monkey patching is that we can optionally disable if for
// customers that choose to enable the legacy extensions.
export function injectNewCodeintel(
old: FlatExtensionHostAPI,
codeintelContext: sourcegraph.CodeIntelContext
): FlatExtensionHostAPI {
const codeintel = createCodeIntelAPI(codeintelContext)
function thenMaybeLoadingResult<T>(promise: Observable<T>): Observable<MaybeLoadingResult<T>> {
return promise.pipe(
map(result => {
const maybeLoadingResult: MaybeLoadingResult<T> = { isLoading: false, result }
return maybeLoadingResult
})
)
}

const codeintelOverrides: Pick<
FlatExtensionHostAPI,
| 'getHover'
| 'getDocumentHighlights'
| 'getReferences'
| 'getDefinition'
| 'getLocations'
| 'hasReferenceProvidersForDocument'
| 'getPanelViews'
> = {
getPanelViews() {
const panels: PanelViewData[] = []
for (const spec of languageSpecs) {
if (spec.textDocumentImplemenationSupport) {
const id = `implementations_${spec.languageID}`
panels.push({
id,
content: '',
component: { locationProvider: id },
selector: selectorForSpec(spec),
priority: 160,
title: 'Implementations',
})
}
}
return proxySubscribable(of(panels))
},
hasReferenceProvidersForDocument(textParameters) {
return proxySubscribable(codeintel.hasReferenceProvidersForDocument(textParameters))
},
getLocations(id, parameters) {
if (!id.startsWith('implementations_')) {
return proxySubscribable(thenMaybeLoadingResult(of([])))
}
return proxySubscribable(thenMaybeLoadingResult(codeintel.getImplementations(parameters)))
},
getDefinition(parameters) {
return proxySubscribable(thenMaybeLoadingResult(codeintel.getDefinition(parameters)))
},
getReferences(parameters, context) {
return proxySubscribable(thenMaybeLoadingResult(codeintel.getReferences(parameters, context)))
},
getDocumentHighlights: (textParameters: TextDocumentPositionParameters) =>
proxySubscribable(codeintel.getDocumentHighlights(textParameters)),
getHover: (textParameters: TextDocumentPositionParameters) =>
proxySubscribable(thenMaybeLoadingResult(codeintel.getHover(textParameters))),
}

return new Proxy(old, {
get(target, prop) {
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-explicit-any
const codeintelFunction = (codeintelOverrides as any)[prop]
if (codeintelFunction) {
return codeintelFunction
}
// eslint-disable-next-line prefer-rest-params
return Reflect.get(target, prop, ...arguments)
},
})
}

This file was deleted.

3 changes: 1 addition & 2 deletions sourcegraph/client/web/src/SourcegraphWebApp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ import { FetchFileParameters, fetchHighlightedFileLineRanges } from '@sourcegrap
import { setCodeIntelSearchContext } from '@sourcegraph/shared/src/codeintel/searchContext'
import { Controller as ExtensionsController } from '@sourcegraph/shared/src/extensions/controller'
import { createController as createExtensionsController } from '@sourcegraph/shared/src/extensions/createLazyLoadedController'
import { createNoopController } from '@sourcegraph/shared/src/extensions/createNoopLoadedController'
import { BrandedNotificationItemStyleProps } from '@sourcegraph/shared/src/notifications/NotificationItem'
import { Notifications } from '@sourcegraph/shared/src/notifications/Notifications'
import { PlatformContext } from '@sourcegraph/shared/src/platform/context'
Expand Down Expand Up @@ -181,7 +180,7 @@ export class SourcegraphWebApp extends React.Component<
private readonly platformContext: PlatformContext = createPlatformContext()
private readonly extensionsController: ExtensionsController | null = window.context.enableLegacyExtensions
? createExtensionsController(this.platformContext)
: createNoopController(this.platformContext)
: null

constructor(props: SourcegraphWebAppProps) {
super(props)
Expand Down

0 comments on commit af119ef

Please sign in to comment.