Skip to content

Commit

Permalink
Merge pull request #34 from mkslanc/ts-extra-libs
Browse files Browse the repository at this point in the history
Ts extra libs
  • Loading branch information
mkslanc authored Jan 31, 2023
2 parents 893168e + 1e7ce0f commit fba48d7
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 11 deletions.
4 changes: 3 additions & 1 deletion packages/ace-linters/language-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,10 @@ export class LanguageProvider {
},
getDocTooltip: (item) => {
if (!item["isResolved"]) {
this.$messageController.doResolve(item["fileName"], toCompletionItem(item), (completionItem) => {
this.$messageController.doResolve(item["fileName"], toCompletionItem(item), (completionItem?) => {
item["isResolved"] = true;
if (!completionItem)
return;
let completion = toResolvedCompletion(item, completionItem);
item.docText = completion.docText;
if (completion.docHTML) {
Expand Down
2 changes: 1 addition & 1 deletion packages/ace-linters/message-controller-ws.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ export class MessageControllerWS extends events.EventEmitter implements IMessage
this.postMessage('textDocument/completion', sessionId, options, completionCallback);
}

doResolve(sessionId: string, completion: lsp.CompletionItem, callback?: (completion: lsp.CompletionItem) => void) {
doResolve(sessionId: string, completion: lsp.CompletionItem, callback?: (completion: lsp.CompletionItem | null) => void) {
if (!this.isInitialized)
return;
if (!this.serverCapabilities?.completionProvider?.resolveProvider)
Expand Down
2 changes: 1 addition & 1 deletion packages/ace-linters/message-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export class MessageController implements IMessageController {
this.postMessage(new CompleteMessage(sessionId, position), callback);
}

doResolve(sessionId: string, completion: lsp.CompletionItem, callback?: (completion: lsp.CompletionItem) => void) {
doResolve(sessionId: string, completion: lsp.CompletionItem, callback?: (completion: lsp.CompletionItem | null) => void) {
this.postMessage(new ResolveCompletionMessage(sessionId, completion), callback);
}

Expand Down
19 changes: 16 additions & 3 deletions packages/ace-linters/services/typescript/typescript-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ export class TypescriptService extends BaseService<TsServiceOptions> implements
allowJs: true,
jsx: JsxEmit.Preserve,
allowNonTsExtensions: true,
target: ScriptTarget.ESNext
target: ScriptTarget.ESNext,
noSemanticValidation: true,
noSyntaxValidation: false,
onlyVisible: false
};

constructor(mode: string) {
Expand All @@ -35,7 +38,12 @@ export class TypescriptService extends BaseService<TsServiceOptions> implements
}

getScriptFileNames(): string[] {
return Object.keys(this.documents);
let fileNames = Object.keys(this.documents);
return fileNames.concat(Object.keys(this.$extraLibs));
}

private get $extraLibs() {
return this.globalOptions["extraLibs"] ?? [];
}

getScriptVersion(fileName: string): string {
Expand Down Expand Up @@ -70,6 +78,8 @@ export class TypescriptService extends BaseService<TsServiceOptions> implements
text = document.getText();
} else if (fileName in libFileMap) {
text = libFileMap[fileName];
} else if (fileName in this.$extraLibs) {
text = this.$extraLibs[fileName].content;
} else {
return;
}
Expand Down Expand Up @@ -204,6 +214,9 @@ export class TypescriptService extends BaseService<TsServiceOptions> implements
undefined
);

return toResolvedCompletion(resolvedCompletion) ?? null;
if (!resolvedCompletion)
return null;

return toResolvedCompletion(resolvedCompletion);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,7 @@ export function toCompletions(completionInfo: CompletionInfo, doc: TextDocument,
});
}

export function toResolvedCompletion(entry?: CompletionEntryDetails): lsp.CompletionItem | undefined {
if (!entry)
return;
export function toResolvedCompletion(entry: CompletionEntryDetails): lsp.CompletionItem {
return {
label: entry.name,
kind: convertKind(entry.kind),
Expand Down
10 changes: 9 additions & 1 deletion packages/ace-linters/types/language-service.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,16 @@ export declare namespace AceLinters {
schemaUri?: string,
}

interface ExtraLib {
content: string;
version: number;
}

export interface TsServiceOptions {
compilerOptions?: ts.CompilerOptions
compilerOptions?: ts.CompilerOptions,
extraLibs?: {
[path: string]: ExtraLib;
}
}

export interface HtmlServiceOptions {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export interface IMessageController {

doComplete(sessionId: string, position: lsp.Position, callback?: (completionList: lsp.CompletionList | lsp.CompletionItem[] | null) => void);

doResolve(sessionId: string, completion: lsp.CompletionItem, callback?: (completion: lsp.CompletionItem) => void);
doResolve(sessionId: string, completion: lsp.CompletionItem, callback?: (completion: lsp.CompletionItem | null) => void);

format(sessionId: string, range: lsp.Range, format: lsp.FormattingOptions, callback?: (edits: lsp.TextEdit[]) => void);

Expand Down

0 comments on commit fba48d7

Please sign in to comment.