Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix type on getCompletionItems #117

Merged
merged 2 commits into from
Feb 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import type { CancellationToken, CompletionContext } from 'vscode-languageserver';
import type { CancellationToken } from 'vscode-languageserver';
import * as lsp from 'vscode-languageserver-types';
import { URI } from 'vscode-uri';
import { getLsConfiguration, LsConfiguration } from './config';
Expand All @@ -17,7 +17,7 @@ import { MdDocumentSymbolProvider } from './languageFeatures/documentSymbols';
import { FileRename, MdFileRenameProvider } from './languageFeatures/fileRename';
import { MdFoldingProvider } from './languageFeatures/folding';
import { MdOrganizeLinkDefinitionProvider } from './languageFeatures/organizeLinkDefs';
import { MdPathCompletionProvider } from './languageFeatures/pathCompletions';
import { PathCompletionOptions, MdPathCompletionProvider } from './languageFeatures/pathCompletions';
import { MdReferencesProvider } from './languageFeatures/references';
import { MdRenameProvider } from './languageFeatures/rename';
import { MdSelectionRangeProvider } from './languageFeatures/smartSelect';
Expand All @@ -32,7 +32,7 @@ export { LsConfiguration, PreferredMdPathExtensionStyle } from './config';
export { DiagnosticCode, DiagnosticLevel, DiagnosticOptions, IPullDiagnosticsManager } from './languageFeatures/diagnostics';
export { ResolvedDocumentLinkTarget } from './languageFeatures/documentLinks';
export { FileRename } from './languageFeatures/fileRename';
export { IncludeWorkspaceHeaderCompletions, MdPathCompletionOptions } from './languageFeatures/pathCompletions';
export { IncludeWorkspaceHeaderCompletions, PathCompletionOptions as MdPathCompletionOptions } from './languageFeatures/pathCompletions';
export { RenameNotSupportedAtLocationError } from './languageFeatures/rename';
export { ILogger, LogLevel } from './logging';
export { IMdParser, Token } from './parser';
Expand Down Expand Up @@ -104,7 +104,7 @@ export interface IMdLanguageService {
/**
* Get completions items at a given position in a markdown file.
*/
getCompletionItems(document: ITextDocument, position: lsp.Position, context: CompletionContext, token: CancellationToken): Promise<lsp.CompletionItem[]>;
getCompletionItems(document: ITextDocument, position: lsp.Position, context: PathCompletionOptions, token: CancellationToken): Promise<lsp.CompletionItem[]>;

/**
* Get the references to a symbol at the current location.
Expand Down
6 changes: 3 additions & 3 deletions src/languageFeatures/pathCompletions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ export enum IncludeWorkspaceHeaderCompletions {
/**
* Control the type of completions returned by a {@link MdPathCompletionProvider}.
*/
export interface MdPathCompletionOptions {
export interface PathCompletionOptions {
/**
* Should header completions for other files in the workspace be returned when
* you trigger completions.
Expand Down Expand Up @@ -161,7 +161,7 @@ export class MdPathCompletionProvider {
this.#workspaceTocCache = new MdWorkspaceInfoCache(workspace, (doc) => tocProvider.getForDocument(doc));
}

public async provideCompletionItems(document: ITextDocument, position: lsp.Position, context: CompletionContext & MdPathCompletionOptions, token: CancellationToken): Promise<lsp.CompletionItem[]> {
public async provideCompletionItems(document: ITextDocument, position: lsp.Position, context: CompletionContext & PathCompletionOptions, token: CancellationToken): Promise<lsp.CompletionItem[]> {
const pathContext = this.#getPathCompletionContext(document, position);
if (!pathContext) {
return [];
Expand All @@ -174,7 +174,7 @@ export class MdPathCompletionProvider {
return items;
}

async *#provideCompletionItems(document: ITextDocument, position: lsp.Position, context: PathCompletionContext, options: MdPathCompletionOptions, token: CancellationToken): AsyncIterable<lsp.CompletionItem> {
async *#provideCompletionItems(document: ITextDocument, position: lsp.Position, context: PathCompletionContext, options: PathCompletionOptions, token: CancellationToken): AsyncIterable<lsp.CompletionItem> {
switch (context.kind) {
case CompletionContextKind.ReferenceLink: {
yield* this.#provideReferenceSuggestions(document, position, context, token);
Expand Down
6 changes: 3 additions & 3 deletions src/test/pathCompletion.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import * as lsp from 'vscode-languageserver-types';
import { URI } from 'vscode-uri';
import { getLsConfiguration, LsConfiguration, PreferredMdPathExtensionStyle } from '../config';
import { MdLinkProvider } from '../languageFeatures/documentLinks';
import { IncludeWorkspaceHeaderCompletions, MdPathCompletionOptions, MdPathCompletionProvider } from '../languageFeatures/pathCompletions';
import { IncludeWorkspaceHeaderCompletions, PathCompletionOptions, MdPathCompletionProvider } from '../languageFeatures/pathCompletions';
import { MdTableOfContentsProvider } from '../tableOfContents';
import { noopToken } from '../util/cancellation';
import { DisposableStore } from '../util/dispose';
Expand All @@ -21,7 +21,7 @@ import { nulLogger } from './nulLogging';
import { CURSOR, getCursorPositions, joinLines, withStore, workspacePath } from './util';


async function getCompletionsAtCursor(store: DisposableStore, doc: InMemoryDocument, workspace: IWorkspace, configOverrides: Partial<LsConfiguration> = {}, context: Partial<MdPathCompletionOptions> = {}) {
async function getCompletionsAtCursor(store: DisposableStore, doc: InMemoryDocument, workspace: IWorkspace, configOverrides: Partial<LsConfiguration> = {}, context: Partial<PathCompletionOptions> = {}) {
const config = getLsConfiguration(configOverrides);

const engine = createNewMarkdownEngine();
Expand All @@ -41,7 +41,7 @@ async function getCompletionsAtCursor(store: DisposableStore, doc: InMemoryDocum
});
}

async function getCompletionsAtCursorForFileContents(store: DisposableStore, uri: URI, fileContents: string, workspace?: IWorkspace, configOverrides: Partial<LsConfiguration> = {}, context: Partial<MdPathCompletionOptions> = {}) {
async function getCompletionsAtCursorForFileContents(store: DisposableStore, uri: URI, fileContents: string, workspace?: IWorkspace, configOverrides: Partial<LsConfiguration> = {}, context: Partial<PathCompletionOptions> = {}) {
const doc = new InMemoryDocument(uri, fileContents);
const ws = workspace ?? store.add(new InMemoryWorkspace([doc]));

Expand Down