This repository has been archived by the owner on Apr 1, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 301
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add completion providers API * Add completion provider to oni api * Refactor to remove old CompletionProvider, which is just 'commitCompletion', and clean up dependencies * Add completion provider API * Fix lint issues * Sync up signature in tests * Fix up signature in test
- Loading branch information
Showing
11 changed files
with
151 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
/** | ||
* CompletionProviders.ts | ||
*/ | ||
|
||
import * as types from "vscode-languageserver-types" | ||
|
||
import { LanguageManager } from "./../Language" | ||
|
||
import { ICompletionsRequestor, LanguageServiceCompletionsRequestor } from "./CompletionsRequestor" | ||
|
||
export interface ICompletionProviderInfo { | ||
id: string | ||
provider: ICompletionsRequestor | ||
} | ||
|
||
export interface ICompletionInfoWithProvider extends types.CompletionItem { | ||
__provider: string | ||
} | ||
|
||
export class CompletionProviders implements ICompletionsRequestor { | ||
private _completionProviders: ICompletionProviderInfo[] = [] | ||
|
||
public registerCompletionProvider(id: string, provider: ICompletionsRequestor): void { | ||
this._completionProviders.push({ | ||
id, | ||
provider, | ||
}) | ||
} | ||
|
||
public async getCompletions(language: string, filePath: string, line: number, column: number): Promise<types.CompletionItem[]> { | ||
const completionItemsPromise = this._completionProviders.map(async (prov) => { | ||
const items = await prov.provider.getCompletions(language, filePath, line, column) | ||
|
||
// Tag the items with the provider id, so we know who to ask for details | ||
const augmentedItems = items.map((item) => { | ||
return { | ||
...item, | ||
__provider: prov.id, | ||
} | ||
}) | ||
|
||
return augmentedItems | ||
}) | ||
|
||
const allItems = await Promise.all(completionItemsPromise) | ||
|
||
const flattenedItems = allItems.reduce((prev: ICompletionInfoWithProvider[], current: ICompletionInfoWithProvider[]) => { | ||
return [...prev, ...current] | ||
}, [] as ICompletionInfoWithProvider[]) | ||
|
||
return flattenedItems | ||
} | ||
|
||
public async getCompletionDetails(language: string, filePath: string, completionItem: ICompletionInfoWithProvider): Promise<types.CompletionItem> { | ||
if (completionItem.__provider) { | ||
const prov = this._getProviderById(completionItem.__provider) | ||
|
||
if (prov && prov.getCompletionDetails) { | ||
return prov.getCompletionDetails(language, filePath, completionItem) | ||
} | ||
} | ||
|
||
return completionItem | ||
} | ||
|
||
private _getProviderById(id: string): ICompletionsRequestor { | ||
const providersMatchingId = this._completionProviders.filter((prov) => prov.id === id) | ||
|
||
return providersMatchingId.length > 0 ? providersMatchingId[0].provider : null | ||
} | ||
} | ||
|
||
let _completionProviders: CompletionProviders | ||
|
||
export const activate = (languageManager: LanguageManager) => { | ||
_completionProviders = new CompletionProviders() | ||
|
||
const languageServiceCompletion = new LanguageServiceCompletionsRequestor(languageManager) | ||
|
||
_completionProviders.registerCompletionProvider("oni.completions.language-server", languageServiceCompletion) | ||
} | ||
|
||
export const getInstance = (): CompletionProviders => { | ||
return _completionProviders | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export * from "./Completion" | ||
export * from "./CompletionProviders" | ||
export * from "./CompletionsRequestor" | ||
export * from "./CompletionUtility" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters