mirror of
https://github.com/microsoft/vscode.git
synced 2026-09-03 07:44:02 +01:00
fix more linter errors
This commit is contained in:
@@ -18,7 +18,7 @@ export class LeftBracket extends SimpleToken<'['> {
|
||||
/**
|
||||
* Return text representation of the token.
|
||||
*/
|
||||
public override get text() {
|
||||
public override get text(): '[' {
|
||||
return LeftBracket.symbol;
|
||||
}
|
||||
|
||||
@@ -43,7 +43,7 @@ export class RightBracket extends SimpleToken<']'> {
|
||||
/**
|
||||
* Return text representation of the token.
|
||||
*/
|
||||
public override get text() {
|
||||
public override get text(): ']' {
|
||||
return RightBracket.symbol;
|
||||
}
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ export class ExclamationMark extends SimpleToken<'!'> {
|
||||
/**
|
||||
* Return text representation of the token.
|
||||
*/
|
||||
public override get text() {
|
||||
public override get text(): '!' {
|
||||
return ExclamationMark.symbol;
|
||||
}
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ export class FormFeed extends SimpleToken<'\f'> {
|
||||
/**
|
||||
* Return text representation of the token.
|
||||
*/
|
||||
public override get text() {
|
||||
public override get text(): '\f' {
|
||||
return FormFeed.symbol;
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,55 @@
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { mockObject } from '../../../../../base/test/common/testUtils.js';
|
||||
import { assertOneOf } from '../../../../../base/common/types.js';
|
||||
|
||||
/**
|
||||
* Mocks an `TObject` with the provided `overrides`.
|
||||
*
|
||||
* If you need to mock an `Service`, please use {@link mockService}
|
||||
* instead which provides better type safety guarantees for the case.
|
||||
*
|
||||
* @throws Reading non-overridden property or function
|
||||
* on `TObject` throws an error.
|
||||
*/
|
||||
export function mockObject<TObject extends object>(
|
||||
overrides: Partial<TObject>,
|
||||
): TObject {
|
||||
// ensure that the overrides object cannot be modified afterward
|
||||
overrides = Object.freeze(overrides);
|
||||
|
||||
const keys: (keyof Partial<TObject>)[] = [];
|
||||
for (const key in overrides) {
|
||||
if (Object.hasOwn(overrides, key)) {
|
||||
keys.push(key);
|
||||
}
|
||||
}
|
||||
|
||||
const service: object = new Proxy(
|
||||
{},
|
||||
{
|
||||
get: <T extends keyof TObject>(
|
||||
_target: TObject,
|
||||
key: string | number | Symbol,
|
||||
): TObject[T] => {
|
||||
|
||||
assertOneOf(
|
||||
key,
|
||||
keys,
|
||||
`The '${key}' is not mocked.`,
|
||||
);
|
||||
|
||||
// TODO: @legomushroom - add type assertion comment
|
||||
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
||||
return overrides[key as T] as TObject[T];
|
||||
},
|
||||
});
|
||||
|
||||
// note! it's ok to `as TObject` here, because of the runtime checks
|
||||
// in the `Proxy` getter
|
||||
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
||||
return service as TObject;
|
||||
}
|
||||
|
||||
/**
|
||||
* Type for any service.
|
||||
|
||||
@@ -28,7 +28,7 @@ export class FileReference extends PromptVariableWithData {
|
||||
* Create a {@link FileReference} from a {@link PromptVariableWithData} instance.
|
||||
* @throws if variable name is not equal to {@link VARIABLE_NAME}.
|
||||
*/
|
||||
public static from(variable: PromptVariableWithData) {
|
||||
public static from(variable: PromptVariableWithData): FileReference {
|
||||
assert(
|
||||
variable.name === VARIABLE_NAME,
|
||||
`Variable name must be '${VARIABLE_NAME}', got '${variable.name}'.`,
|
||||
|
||||
+2
-2
@@ -46,7 +46,7 @@ export class FilePromptContentProvider extends PromptContentsProviderBase<FileCh
|
||||
|
||||
constructor(
|
||||
public readonly uri: URI,
|
||||
options: Partial<IPromptContentsProviderOptions> = {},
|
||||
options: Partial<IPromptContentsProviderOptions>,
|
||||
@IFileService private readonly fileService: IFileService,
|
||||
@IModelService private readonly modelService: IModelService,
|
||||
@ILanguageService private readonly languageService: ILanguageService,
|
||||
@@ -152,7 +152,7 @@ export class FilePromptContentProvider extends PromptContentsProviderBase<FileCh
|
||||
/**
|
||||
* String representation of this object.
|
||||
*/
|
||||
public override toString() {
|
||||
public override toString(): string {
|
||||
return `file-prompt-contents-provider:${this.uri.path}`;
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -38,7 +38,7 @@ export class TextModelContentsProvider extends PromptContentsProviderBase<IModel
|
||||
|
||||
constructor(
|
||||
private readonly model: ITextModel,
|
||||
options: Partial<IPromptContentsProviderOptions> = {},
|
||||
options: Partial<IPromptContentsProviderOptions>,
|
||||
@IInstantiationService private readonly initService: IInstantiationService,
|
||||
@ILogService private readonly logService: ILogService,
|
||||
) {
|
||||
@@ -149,7 +149,7 @@ export class TextModelContentsProvider extends PromptContentsProviderBase<IModel
|
||||
/**
|
||||
* String representation of this object.
|
||||
*/
|
||||
public override toString() {
|
||||
public override toString(): string {
|
||||
return `text-model-prompt-contents-provider:${this.uri.path}`;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,9 +12,8 @@ import { IWorkbenchContributionsRegistry, Extensions, IWorkbenchContribution } f
|
||||
/**
|
||||
* Function that registers all prompt-file related contributions.
|
||||
*/
|
||||
export const registerPromptFileContributions = () => {
|
||||
export const registerPromptFileContributions = (): void => {
|
||||
registerContributions(LANGUAGE_FEATURE_CONTRIBUTIONS);
|
||||
|
||||
registerContribution(ConfigMigration);
|
||||
};
|
||||
|
||||
@@ -26,9 +25,7 @@ export type TContribution = new (...args: any[]) => IWorkbenchContribution;
|
||||
/**
|
||||
* Register a specific workbench contribution.
|
||||
*/
|
||||
const registerContribution = (
|
||||
contribution: TContribution,
|
||||
) => {
|
||||
const registerContribution = (contribution: TContribution): void => {
|
||||
Registry.as<IWorkbenchContributionsRegistry>(Extensions.Workbench)
|
||||
.registerWorkbenchContribution(contribution, LifecyclePhase.Eventually);
|
||||
};
|
||||
@@ -36,9 +33,7 @@ const registerContribution = (
|
||||
/**
|
||||
* Register a specific workbench contribution.
|
||||
*/
|
||||
const registerContributions = (
|
||||
contributions: readonly TContribution[],
|
||||
) => {
|
||||
const registerContributions = (contributions: readonly TContribution[]): void => {
|
||||
contributions
|
||||
.map(registerContribution);
|
||||
.forEach(registerContribution);
|
||||
};
|
||||
|
||||
+2
-2
@@ -8,7 +8,7 @@ import { localize } from '../../../../../../../../../../nls.js';
|
||||
import { FrontMatterMarkerDecoration } from './frontMatterMarkerDecoration.js';
|
||||
import { Position } from '../../../../../../../../../../editor/common/core/position.js';
|
||||
import { BaseToken } from '../../../../../../../../../../editor/common/codecs/baseToken.js';
|
||||
import { TAddAccessor, TDecorationStyles, ReactiveDecorationBase, asCssVariable } from './utils/index.js';
|
||||
import { TAddAccessor, TDecorationStyles, ReactiveDecorationBase, asCssVariable, IReactiveDecorationClassNames } from './utils/index.js';
|
||||
import { contrastBorder, editorBackground } from '../../../../../../../../../../platform/theme/common/colorRegistry.js';
|
||||
import { ColorIdentifier, darken, registerColor } from '../../../../../../../../../../platform/theme/common/colorUtils.js';
|
||||
import { FrontMatterHeader } from '../../../../../../../../../../editor/common/codecs/markdownExtensionsCodec/tokens/frontMatterHeader.js';
|
||||
@@ -92,7 +92,7 @@ export class FrontMatterDecoration extends ReactiveDecorationBase<FrontMatterHea
|
||||
return result;
|
||||
}
|
||||
|
||||
protected override get classNames() {
|
||||
protected override get classNames(): IReactiveDecorationClassNames<CssClassNames> {
|
||||
return CssClassNames;
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -4,7 +4,7 @@
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { CssClassModifiers } from '../types.js';
|
||||
import { TDecorationStyles, ReactiveDecorationBase } from './utils/index.js';
|
||||
import { TDecorationStyles, ReactiveDecorationBase, IReactiveDecorationClassNames } from './utils/index.js';
|
||||
import { FrontMatterMarker } from '../../../../../../../../../../editor/common/codecs/markdownExtensionsCodec/tokens/frontMatterMarker.js';
|
||||
|
||||
/**
|
||||
@@ -34,7 +34,7 @@ export class FrontMatterMarkerDecoration extends ReactiveDecorationBase<FrontMat
|
||||
return this;
|
||||
}
|
||||
|
||||
protected override get classNames() {
|
||||
protected override get classNames(): IReactiveDecorationClassNames<CssClassNames> {
|
||||
return CssClassNames;
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -143,13 +143,13 @@ export abstract class ReactiveDecorationBase<
|
||||
return this;
|
||||
}
|
||||
|
||||
protected override get className() {
|
||||
protected override get className(): TCssClassName {
|
||||
return (this.active)
|
||||
? this.classNames.main
|
||||
: this.classNames.mainInactive;
|
||||
}
|
||||
|
||||
protected override get inlineClassName() {
|
||||
protected override get inlineClassName(): TCssClassName {
|
||||
return (this.active)
|
||||
? this.classNames.inline
|
||||
: this.classNames.inlineInactive;
|
||||
|
||||
+3
-3
@@ -8,9 +8,9 @@ import { ProviderInstanceBase } from '../providerInstanceBase.js';
|
||||
import { ITextModel } from '../../../../../../../../../editor/common/model.js';
|
||||
import { FrontMatterDecoration } from './decorations/frontMatterDecoration.js';
|
||||
import { toDisposable } from '../../../../../../../../../base/common/lifecycle.js';
|
||||
import { ProviderInstanceManagerBase } from '../providerInstanceManagerBase.js';
|
||||
import { Position } from '../../../../../../../../../editor/common/core/position.js';
|
||||
import { BaseToken } from '../../../../../../../../../editor/common/codecs/baseToken.js';
|
||||
import { ProviderInstanceManagerBase, TProviderInstance } from '../providerInstanceManagerBase.js';
|
||||
import { registerThemingParticipant } from '../../../../../../../../../platform/theme/common/themeService.js';
|
||||
import { FrontMatterHeader } from '../../../../../../../../../editor/common/codecs/markdownExtensionsCodec/tokens/frontMatterHeader.js';
|
||||
import { DecorationBase, ReactiveDecorationBase, type TDecorationClass, type TChangedDecorator } from './decorations/utils/index.js';
|
||||
@@ -178,7 +178,7 @@ export class PromptDecorator extends ProviderInstanceBase {
|
||||
/**
|
||||
* Returns a string representation of this object.
|
||||
*/
|
||||
public override toString() {
|
||||
public override toString(): string {
|
||||
return `text-model-prompt-decorator:${this.model.uri.path}`;
|
||||
}
|
||||
}
|
||||
@@ -198,7 +198,7 @@ registerThemingParticipant((_theme, collector) => {
|
||||
* Provider for prompt syntax decorators on text models.
|
||||
*/
|
||||
export class PromptDecorationsProviderInstanceManager extends ProviderInstanceManagerBase<PromptDecorator> {
|
||||
protected override get InstanceClass() {
|
||||
protected override get InstanceClass(): TProviderInstance<PromptDecorator> {
|
||||
return PromptDecorator;
|
||||
}
|
||||
}
|
||||
|
||||
+3
-3
@@ -7,7 +7,7 @@ import { IPromptsService } from '../../../service/types.js';
|
||||
import { ProviderInstanceBase } from './providerInstanceBase.js';
|
||||
import { assertNever } from '../../../../../../../../base/common/assert.js';
|
||||
import { ITextModel } from '../../../../../../../../editor/common/model.js';
|
||||
import { ProviderInstanceManagerBase } from './providerInstanceManagerBase.js';
|
||||
import { ProviderInstanceManagerBase, TProviderInstance } from './providerInstanceManagerBase.js';
|
||||
import { TDiagnostic, PromptMetadataError, PromptMetadataWarning } from '../../../parsers/promptHeader/diagnostics.js';
|
||||
import { IMarkerData, IMarkerService, MarkerSeverity } from '../../../../../../../../platform/markers/common/markers.js';
|
||||
|
||||
@@ -61,7 +61,7 @@ class PromptHeaderDiagnosticsProvider extends ProviderInstanceBase {
|
||||
/**
|
||||
* Returns a string representation of this object.
|
||||
*/
|
||||
public override toString() {
|
||||
public override toString(): string {
|
||||
return `prompt-link-diagnostics:${this.model.uri.path}`;
|
||||
}
|
||||
}
|
||||
@@ -100,7 +100,7 @@ const toMarker = (
|
||||
* classes for each specific editor text model.
|
||||
*/
|
||||
export class PromptHeaderDiagnosticsInstanceManager extends ProviderInstanceManagerBase<PromptHeaderDiagnosticsProvider> {
|
||||
protected override get InstanceClass() {
|
||||
protected override get InstanceClass(): TProviderInstance<PromptHeaderDiagnosticsProvider> {
|
||||
return PromptHeaderDiagnosticsProvider;
|
||||
}
|
||||
}
|
||||
|
||||
+4
-4
@@ -10,7 +10,7 @@ import { assert } from '../../../../../../../../base/common/assert.js';
|
||||
import { NotPromptFile } from '../../../../promptFileReferenceErrors.js';
|
||||
import { ITextModel } from '../../../../../../../../editor/common/model.js';
|
||||
import { assertDefined } from '../../../../../../../../base/common/types.js';
|
||||
import { ProviderInstanceManagerBase } from './providerInstanceManagerBase.js';
|
||||
import { ProviderInstanceManagerBase, TProviderInstance } from './providerInstanceManagerBase.js';
|
||||
import { IMarkerData, IMarkerService, MarkerSeverity } from '../../../../../../../../platform/markers/common/markers.js';
|
||||
|
||||
/**
|
||||
@@ -33,7 +33,7 @@ class PromptLinkDiagnosticsProvider extends ProviderInstanceBase {
|
||||
/**
|
||||
* Update diagnostic markers for the current editor.
|
||||
*/
|
||||
protected override async onPromptSettled() {
|
||||
protected override async onPromptSettled(): Promise<this> {
|
||||
// ensure that parsing process is settled
|
||||
await this.parser.allSettled();
|
||||
|
||||
@@ -72,7 +72,7 @@ class PromptLinkDiagnosticsProvider extends ProviderInstanceBase {
|
||||
/**
|
||||
* Returns a string representation of this object.
|
||||
*/
|
||||
public override toString() {
|
||||
public override toString(): string {
|
||||
return `prompt-link-diagnostics:${this.model.uri.path}`;
|
||||
}
|
||||
}
|
||||
@@ -125,7 +125,7 @@ const toMarker = (
|
||||
* classes for each specific editor text model.
|
||||
*/
|
||||
export class PromptLinkDiagnosticsInstanceManager extends ProviderInstanceManagerBase<PromptLinkDiagnosticsProvider> {
|
||||
protected override get InstanceClass() {
|
||||
protected override get InstanceClass(): TProviderInstance<PromptLinkDiagnosticsProvider> {
|
||||
return PromptLinkDiagnosticsProvider;
|
||||
}
|
||||
}
|
||||
|
||||
+6
-1
@@ -24,6 +24,11 @@ export interface IPromptFileEditor extends IEditor {
|
||||
readonly getModel: () => ITextModel;
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO: @legomushroom
|
||||
*/
|
||||
export type TProviderInstance<TInstance extends ProviderInstanceBase> = new (editor: ITextModel, ...args: any[]) => TInstance;
|
||||
|
||||
/**
|
||||
* A generic base class that manages creation and disposal of {@link TInstance}
|
||||
* objects for each specific editor object that is used for reusable prompt files.
|
||||
@@ -37,7 +42,7 @@ export abstract class ProviderInstanceManagerBase<TInstance extends ProviderInst
|
||||
/**
|
||||
* Class object of the managed {@link TInstance}.
|
||||
*/
|
||||
protected abstract get InstanceClass(): new (editor: ITextModel, ...args: any[]) => TInstance;
|
||||
protected abstract get InstanceClass(): TProviderInstance<TInstance>;
|
||||
|
||||
constructor(
|
||||
@IModelService modelService: IModelService,
|
||||
|
||||
@@ -171,7 +171,7 @@ export class BasePromptParser<TContentsProvider extends IPromptContentsProvider>
|
||||
* The promise is resolved when at least one parse result (a stream or
|
||||
* an error) has been received from the prompt contents provider.
|
||||
*/
|
||||
private firstParseResult = new FirstParseResult();
|
||||
private readonly firstParseResult = new FirstParseResult();
|
||||
|
||||
/**
|
||||
* Returned promise is resolved when the parser process is settled.
|
||||
@@ -445,7 +445,7 @@ export class BasePromptParser<TContentsProvider extends IPromptContentsProvider>
|
||||
/**
|
||||
* Dispose all currently held references.
|
||||
*/
|
||||
private disposeReferences() {
|
||||
private disposeReferences(): void {
|
||||
for (const reference of [...this._references]) {
|
||||
reference.dispose();
|
||||
}
|
||||
@@ -753,7 +753,7 @@ export class BasePromptParser<TContentsProvider extends IPromptContentsProvider>
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public override dispose() {
|
||||
public override dispose(): void {
|
||||
if (this.disposed) {
|
||||
return;
|
||||
}
|
||||
@@ -784,7 +784,7 @@ export class PromptReference extends ObservableDisposable implements TPromptRefe
|
||||
constructor(
|
||||
private readonly promptContentsProvider: IPromptContentsProvider,
|
||||
public readonly token: FileReference | MarkdownLink,
|
||||
options: Partial<IPromptParserOptions> = {},
|
||||
options: Partial<IPromptParserOptions>,
|
||||
@IInstantiationService initService: IInstantiationService,
|
||||
) {
|
||||
super();
|
||||
@@ -945,7 +945,7 @@ export class PromptReference extends ObservableDisposable implements TPromptRefe
|
||||
/**
|
||||
* Returns a string representation of this object.
|
||||
*/
|
||||
public override toString() {
|
||||
public override toString(): string {
|
||||
return `prompt-reference/${this.type}:${this.subtype}/${this.token}`;
|
||||
}
|
||||
}
|
||||
@@ -978,7 +978,7 @@ class FirstParseResult extends DeferredPromise<void> {
|
||||
/**
|
||||
* Complete the underlying promise.
|
||||
*/
|
||||
public override complete() {
|
||||
public override complete(): Promise<void> {
|
||||
this._gotResult = true;
|
||||
return super.complete(void 0);
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ import { IInstantiationService } from '../../../../../../platform/instantiation/
|
||||
export class FilePromptParser extends BasePromptParser<FilePromptContentProvider> {
|
||||
constructor(
|
||||
uri: URI,
|
||||
options: Partial<IPromptParserOptions> = {},
|
||||
options: Partial<IPromptParserOptions>,
|
||||
@IInstantiationService initService: IInstantiationService,
|
||||
@IWorkspaceContextService workspaceService: IWorkspaceContextService,
|
||||
@ILogService logService: ILogService,
|
||||
@@ -31,7 +31,7 @@ export class FilePromptParser extends BasePromptParser<FilePromptContentProvider
|
||||
/**
|
||||
* Returns a string representation of this object.
|
||||
*/
|
||||
public override toString() {
|
||||
public override toString(): string {
|
||||
return `file-prompt:${this.uri.path}`;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,7 +53,7 @@ export class PromptParser extends BasePromptParser<IPromptContentsProvider> {
|
||||
|
||||
constructor(
|
||||
uri: URI,
|
||||
options: Partial<IPromptParserOptions> = {},
|
||||
options: Partial<IPromptParserOptions>,
|
||||
@ILogService logService: ILogService,
|
||||
@IModelService modelService: IModelService,
|
||||
@IInstantiationService instaService: IInstantiationService,
|
||||
@@ -75,7 +75,7 @@ export class PromptParser extends BasePromptParser<IPromptContentsProvider> {
|
||||
/**
|
||||
* Returns a string representation of this object.
|
||||
*/
|
||||
public override toString() {
|
||||
public override toString(): string {
|
||||
const { sourceName } = this.contentsProvider;
|
||||
|
||||
return `prompt-parser:${sourceName}:${this.uri.path}`;
|
||||
|
||||
@@ -17,7 +17,7 @@ import { IInstantiationService } from '../../../../../../platform/instantiation/
|
||||
export class TextModelPromptParser extends BasePromptParser<TextModelContentsProvider> {
|
||||
constructor(
|
||||
model: ITextModel,
|
||||
options: Partial<IPromptParserOptions> = {},
|
||||
options: Partial<IPromptParserOptions>,
|
||||
@IInstantiationService initService: IInstantiationService,
|
||||
@IWorkspaceContextService workspaceService: IWorkspaceContextService,
|
||||
@ILogService logService: ILogService,
|
||||
@@ -36,7 +36,7 @@ export class TextModelPromptParser extends BasePromptParser<TextModelContentsPro
|
||||
/**
|
||||
* Returns a string representation of this object.
|
||||
*/
|
||||
public override toString() {
|
||||
public override toString(): string {
|
||||
return `text-model-prompt:${this.uri.path}`;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ export class TopError implements ITopError {
|
||||
public readonly parentUri: ITopError['parentUri'];
|
||||
|
||||
constructor(
|
||||
readonly options: Omit<ITopError, 'localizedMessage'>,
|
||||
options: Omit<ITopError, 'localizedMessage'>,
|
||||
) {
|
||||
this.originalError = options.originalError;
|
||||
this.errorSubject = options.errorSubject;
|
||||
|
||||
@@ -39,9 +39,9 @@ export const forEach = <TTreeNode>(
|
||||
}
|
||||
|
||||
for (const child of treeRoot.children ?? []) {
|
||||
const shouldStop = forEach(callback, child);
|
||||
const childShouldStop = forEach(callback, child);
|
||||
|
||||
if (shouldStop === true) {
|
||||
if (childShouldStop === true) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user