2014-07-19 01:55:11 +02:00
|
|
|
//
|
|
|
|
// Copyright (c) Microsoft Corporation. All rights reserved.
|
2015-05-05 22:36:59 +02:00
|
|
|
//
|
2014-07-19 01:55:11 +02:00
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
//
|
2014-07-13 01:04:16 +02:00
|
|
|
|
2015-04-09 23:18:14 +02:00
|
|
|
/* @internal */
|
2021-08-16 22:53:51 +02:00
|
|
|
let debugObjectHost: { CollectGarbage(): void } = (function (this: any) { // eslint-disable-line prefer-const
|
|
|
|
return this;
|
|
|
|
})();
|
2016-01-08 05:13:41 +01:00
|
|
|
|
|
|
|
// We need to use 'null' to interface with the managed side.
|
2019-07-24 06:17:16 +02:00
|
|
|
/* eslint-disable no-in-operator */
|
2014-07-25 20:21:17 +02:00
|
|
|
|
2015-04-09 23:18:14 +02:00
|
|
|
/* @internal */
|
2015-06-12 18:01:48 +02:00
|
|
|
namespace ts {
|
2017-11-21 01:43:02 +01:00
|
|
|
interface DiscoverTypingsInfo {
|
|
|
|
fileNames: string[]; // The file names that belong to the same project.
|
|
|
|
projectRootPath: string; // The path to the project root directory
|
|
|
|
safeListPath: string; // The path used to retrieve the safe list
|
2020-07-02 02:00:26 +02:00
|
|
|
packageNameToTypingLocation: ESMap<string, JsTyping.CachedTyping>; // The map of package names to their cached typing locations and installed versions
|
2017-11-21 01:43:02 +01:00
|
|
|
typeAcquisition: TypeAcquisition; // Used to customize the type acquisition process
|
|
|
|
compilerOptions: CompilerOptions; // Used as a source for typing inference
|
2019-08-08 20:30:18 +02:00
|
|
|
unresolvedImports: readonly string[]; // List of unresolved module ids from imports
|
2020-07-02 02:00:26 +02:00
|
|
|
typesRegistry: ReadonlyESMap<string, MapLike<string>>; // The map of available typings in npm to maps of TS versions to their latest supported versions
|
2017-11-21 01:43:02 +01:00
|
|
|
}
|
|
|
|
|
2014-07-25 01:03:48 +02:00
|
|
|
export interface ScriptSnapshotShim {
|
2014-09-25 00:27:17 +02:00
|
|
|
/** Gets a portion of the script snapshot specified by [start, end). */
|
2014-07-13 01:04:16 +02:00
|
|
|
getText(start: number, end: number): string;
|
|
|
|
|
2014-09-25 00:27:17 +02:00
|
|
|
/** Gets the length of this script snapshot. */
|
2014-07-13 01:04:16 +02:00
|
|
|
getLength(): number;
|
|
|
|
|
2014-09-24 21:55:27 +02:00
|
|
|
/**
|
2014-09-25 00:27:17 +02:00
|
|
|
* Returns a JSON-encoded value of the type:
|
2014-09-24 21:55:27 +02:00
|
|
|
* { span: { start: number; length: number }; newLength: number }
|
|
|
|
*
|
2014-09-25 00:27:17 +02:00
|
|
|
* Or undefined value if there was no change.
|
2014-09-24 21:55:27 +02:00
|
|
|
*/
|
2017-04-05 20:39:59 +02:00
|
|
|
getChangeRange(oldSnapshot: ScriptSnapshotShim): string | undefined;
|
2015-07-01 01:11:09 +02:00
|
|
|
|
|
|
|
/** Releases all resources held by this script snapshot */
|
|
|
|
dispose?(): void;
|
2014-07-19 01:55:11 +02:00
|
|
|
}
|
|
|
|
|
2015-01-15 02:05:50 +01:00
|
|
|
export interface Logger {
|
|
|
|
log(s: string): void;
|
|
|
|
trace(s: string): void;
|
|
|
|
error(s: string): void;
|
|
|
|
}
|
|
|
|
|
2017-04-03 18:32:39 +02:00
|
|
|
/** Public interface of the host of a language service shim instance. */
|
2014-07-25 01:01:51 +02:00
|
|
|
export interface LanguageServiceShimHost extends Logger {
|
2014-07-19 01:55:11 +02:00
|
|
|
getCompilationSettings(): string;
|
|
|
|
|
2014-09-25 00:27:17 +02:00
|
|
|
/** Returns a JSON-encoded value of the type: string[] */
|
2014-07-19 01:55:11 +02:00
|
|
|
getScriptFileNames(): string;
|
2016-02-17 07:44:43 +01:00
|
|
|
getScriptKind?(fileName: string): ScriptKind;
|
2014-08-15 02:49:02 +02:00
|
|
|
getScriptVersion(fileName: string): string;
|
2014-07-25 01:03:48 +02:00
|
|
|
getScriptSnapshot(fileName: string): ScriptSnapshotShim;
|
2014-07-19 01:55:11 +02:00
|
|
|
getLocalizedDiagnosticMessages(): string;
|
2015-06-18 21:04:26 +02:00
|
|
|
getCancellationToken(): HostCancellationToken;
|
2014-09-16 22:19:49 +02:00
|
|
|
getCurrentDirectory(): string;
|
2016-07-08 01:10:20 +02:00
|
|
|
getDirectories(path: string): string;
|
2015-02-04 01:08:46 +01:00
|
|
|
getDefaultLibFileName(options: string): string;
|
2015-02-05 08:20:26 +01:00
|
|
|
getNewLine?(): string;
|
2015-05-12 19:57:55 +02:00
|
|
|
getProjectVersion?(): string;
|
2015-06-03 22:48:34 +02:00
|
|
|
useCaseSensitiveFileNames?(): boolean;
|
2015-12-24 09:21:03 +01:00
|
|
|
|
2016-09-20 01:47:15 +02:00
|
|
|
getTypeRootsVersion?(): number;
|
2016-08-04 20:10:00 +02:00
|
|
|
readDirectory(rootDir: string, extension: string, basePaths?: string, excludeEx?: string, includeFileEx?: string, includeDirEx?: string, depth?: number): string;
|
2017-07-14 23:26:13 +02:00
|
|
|
readFile(path: string, encoding?: string): string | undefined;
|
2016-06-24 22:56:45 +02:00
|
|
|
fileExists(path: string): boolean;
|
|
|
|
|
2015-08-07 01:23:10 +02:00
|
|
|
getModuleResolutionsForFile?(fileName: string): string;
|
2016-04-01 21:41:01 +02:00
|
|
|
getTypeReferenceDirectiveResolutionsForFile?(fileName: string): string;
|
2016-01-06 21:37:52 +01:00
|
|
|
directoryExists(directoryName: string): boolean;
|
2014-07-19 01:55:11 +02:00
|
|
|
}
|
|
|
|
|
2016-08-04 16:43:54 +02:00
|
|
|
/** Public interface of the core-services host instance used in managed side */
|
|
|
|
export interface CoreServicesShimHost extends Logger {
|
|
|
|
directoryExists(directoryName: string): boolean;
|
|
|
|
fileExists(fileName: string): boolean;
|
|
|
|
getCurrentDirectory(): string;
|
|
|
|
getDirectories(path: string): string;
|
|
|
|
|
2015-07-15 23:19:54 +02:00
|
|
|
/**
|
|
|
|
* Returns a JSON-encoded value of the type: string[]
|
2015-06-18 06:22:16 +02:00
|
|
|
*
|
|
|
|
* @param exclude A JSON encoded string[] containing the paths to exclude
|
|
|
|
* when enumerating the directory.
|
|
|
|
*/
|
2016-05-31 19:11:04 +02:00
|
|
|
readDirectory(rootDir: string, extension: string, basePaths?: string, excludeEx?: string, includeFileEx?: string, includeDirEx?: string, depth?: number): string;
|
2016-08-04 16:43:54 +02:00
|
|
|
|
|
|
|
/**
|
2018-06-29 04:01:46 +02:00
|
|
|
* Read arbitrary text files on disk, i.e. when resolution procedure needs the content of 'package.json' to determine location of bundled typings for node modules
|
2016-08-04 16:43:54 +02:00
|
|
|
*/
|
2017-07-14 23:26:13 +02:00
|
|
|
readFile(fileName: string): string | undefined;
|
2016-08-04 16:43:54 +02:00
|
|
|
realpath?(path: string): string;
|
2015-11-20 06:33:33 +01:00
|
|
|
trace(s: string): void;
|
2016-08-04 16:43:54 +02:00
|
|
|
useCaseSensitiveFileNames?(): boolean;
|
2015-04-21 22:24:02 +02:00
|
|
|
}
|
|
|
|
|
2014-10-28 22:45:32 +01:00
|
|
|
///
|
|
|
|
/// Pre-processing
|
|
|
|
///
|
|
|
|
// Note: This is being using by the host (VS) and is marshaled back and forth.
|
|
|
|
// When changing this make sure the changes are reflected in the managed side as well
|
2017-11-03 01:20:18 +01:00
|
|
|
export interface ShimsFileReference {
|
2014-10-28 22:45:32 +01:00
|
|
|
path: string;
|
|
|
|
position: number;
|
|
|
|
length: number;
|
|
|
|
}
|
|
|
|
|
2014-09-24 21:55:27 +02:00
|
|
|
/** Public interface of a language service instance shim. */
|
2014-07-24 21:00:45 +02:00
|
|
|
export interface ShimFactory {
|
|
|
|
registerShim(shim: Shim): void;
|
|
|
|
unregisterShim(shim: Shim): void;
|
2014-07-19 01:55:11 +02:00
|
|
|
}
|
|
|
|
|
2014-07-24 21:00:45 +02:00
|
|
|
export interface Shim {
|
2017-10-10 19:54:29 +02:00
|
|
|
dispose(_dummy: {}): void;
|
2014-07-19 01:55:11 +02:00
|
|
|
}
|
2015-05-05 22:36:59 +02:00
|
|
|
|
2014-07-24 21:00:45 +02:00
|
|
|
export interface LanguageServiceShim extends Shim {
|
2014-07-24 20:57:18 +02:00
|
|
|
languageService: LanguageService;
|
2014-07-19 01:55:11 +02:00
|
|
|
|
2017-10-10 19:54:29 +02:00
|
|
|
dispose(_dummy: {}): void;
|
2014-07-19 01:55:11 +02:00
|
|
|
|
|
|
|
refresh(throwOnError: boolean): void;
|
|
|
|
|
|
|
|
cleanupSemanticCache(): void;
|
|
|
|
|
|
|
|
getSyntacticDiagnostics(fileName: string): string;
|
|
|
|
getSemanticDiagnostics(fileName: string): string;
|
2018-02-28 20:16:32 +01:00
|
|
|
getSuggestionDiagnostics(fileName: string): string;
|
2014-07-19 01:55:11 +02:00
|
|
|
getCompilerOptionsDiagnostics(): string;
|
|
|
|
|
2014-09-13 02:19:48 +02:00
|
|
|
getSyntacticClassifications(fileName: string, start: number, length: number): string;
|
2020-09-11 21:10:55 +02:00
|
|
|
getSemanticClassifications(fileName: string, start: number, length: number, format?: SemanticClassificationFormat): string;
|
2015-05-01 02:39:51 +02:00
|
|
|
getEncodedSyntacticClassifications(fileName: string, start: number, length: number): string;
|
2020-09-11 21:10:55 +02:00
|
|
|
getEncodedSemanticClassifications(fileName: string, start: number, length: number, format?: SemanticClassificationFormat): string;
|
2014-09-13 02:19:48 +02:00
|
|
|
|
2021-11-16 01:39:52 +01:00
|
|
|
getCompletionsAtPosition(fileName: string, position: number, preferences: UserPreferences | undefined, formattingSettings: FormatCodeSettings | undefined): string;
|
2021-03-01 21:09:45 +01:00
|
|
|
getCompletionEntryDetails(fileName: string, position: number, entryName: string, formatOptions: string/*Services.FormatCodeOptions*/ | undefined, source: string | undefined, preferences: UserPreferences | undefined, data: CompletionEntryData | undefined): string;
|
2014-07-19 01:55:11 +02:00
|
|
|
|
2014-09-20 00:32:27 +02:00
|
|
|
getQuickInfoAtPosition(fileName: string, position: number): string;
|
2014-09-26 20:10:46 +02:00
|
|
|
|
2014-07-19 01:55:11 +02:00
|
|
|
getNameOrDottedNameSpan(fileName: string, startPos: number, endPos: number): string;
|
|
|
|
getBreakpointStatementAtPosition(fileName: string, position: number): string;
|
2014-08-15 01:51:16 +02:00
|
|
|
|
2018-06-13 00:36:53 +02:00
|
|
|
getSignatureHelpItems(fileName: string, position: number, options: SignatureHelpItemsOptions | undefined): string;
|
2014-08-15 01:51:16 +02:00
|
|
|
|
2014-09-24 21:55:27 +02:00
|
|
|
/**
|
2014-09-25 00:27:17 +02:00
|
|
|
* Returns a JSON-encoded value of the type:
|
2014-09-24 21:55:27 +02:00
|
|
|
* { canRename: boolean, localizedErrorMessage: string, displayName: string, fullDisplayName: string, kind: string, kindModifiers: string, triggerSpan: { start; length } }
|
|
|
|
*/
|
2019-01-11 23:45:08 +01:00
|
|
|
getRenameInfo(fileName: string, position: number, options?: RenameInfoOptions): string;
|
2019-04-19 01:23:06 +02:00
|
|
|
getSmartSelectionRange(fileName: string, position: number): string;
|
2014-07-19 01:55:11 +02:00
|
|
|
|
2014-10-03 23:53:50 +02:00
|
|
|
/**
|
|
|
|
* Returns a JSON-encoded value of the type:
|
|
|
|
* { fileName: string, textSpan: { start: number, length: number } }[]
|
|
|
|
*/
|
2019-01-16 19:58:07 +01:00
|
|
|
findRenameLocations(fileName: string, position: number, findInStrings: boolean, findInComments: boolean, providePrefixAndSuffixTextForRename?: boolean): string;
|
2014-10-03 23:53:50 +02:00
|
|
|
|
2014-09-24 21:55:27 +02:00
|
|
|
/**
|
2014-09-25 00:27:17 +02:00
|
|
|
* Returns a JSON-encoded value of the type:
|
2014-09-24 21:55:27 +02:00
|
|
|
* { fileName: string; textSpan: { start: number; length: number}; kind: string; name: string; containerKind: string; containerName: string }
|
|
|
|
*
|
2014-09-25 00:27:17 +02:00
|
|
|
* Or undefined value if no definition can be found.
|
2014-09-24 21:55:27 +02:00
|
|
|
*/
|
2014-07-19 01:55:11 +02:00
|
|
|
getDefinitionAtPosition(fileName: string, position: number): string;
|
|
|
|
|
2017-10-18 23:48:06 +02:00
|
|
|
getDefinitionAndBoundSpan(fileName: string, position: number): string;
|
|
|
|
|
2015-04-30 07:06:24 +02:00
|
|
|
/**
|
|
|
|
* Returns a JSON-encoded value of the type:
|
|
|
|
* { fileName: string; textSpan: { start: number; length: number}; kind: string; name: string; containerKind: string; containerName: string }
|
|
|
|
*
|
|
|
|
* Or undefined value if no definition can be found.
|
|
|
|
*/
|
|
|
|
getTypeDefinitionAtPosition(fileName: string, position: number): string;
|
|
|
|
|
2016-08-22 22:57:40 +02:00
|
|
|
/**
|
|
|
|
* Returns a JSON-encoded value of the type:
|
2016-09-14 02:33:49 +02:00
|
|
|
* { fileName: string; textSpan: { start: number; length: number}; }[]
|
2016-08-22 22:57:40 +02:00
|
|
|
*/
|
|
|
|
getImplementationAtPosition(fileName: string, position: number): string;
|
|
|
|
|
2014-09-24 21:55:27 +02:00
|
|
|
/**
|
2014-09-25 00:27:17 +02:00
|
|
|
* Returns a JSON-encoded value of the type:
|
2016-06-13 22:21:47 +02:00
|
|
|
* { fileName: string; textSpan: { start: number; length: number}; isWriteAccess: boolean, isDefinition?: boolean }[]
|
2014-09-24 21:55:27 +02:00
|
|
|
*/
|
2014-07-19 01:55:11 +02:00
|
|
|
getReferencesAtPosition(fileName: string, position: number): string;
|
2015-05-05 22:36:59 +02:00
|
|
|
|
2015-03-20 22:31:36 +01:00
|
|
|
/**
|
|
|
|
* Returns a JSON-encoded value of the type:
|
|
|
|
* { definition: <encoded>; references: <encoded>[] }[]
|
|
|
|
*/
|
|
|
|
findReferences(fileName: string, position: number): string;
|
2014-07-19 01:55:11 +02:00
|
|
|
|
2020-12-11 21:37:02 +01:00
|
|
|
/**
|
|
|
|
* Returns a JSON-encoded value of the type:
|
|
|
|
* { fileName: string; textSpan: { start: number; length: number}; isWriteAccess: boolean, isDefinition?: boolean }[]
|
|
|
|
*/
|
|
|
|
getFileReferences(fileName: string): string;
|
|
|
|
|
2014-09-24 21:55:27 +02:00
|
|
|
/**
|
2015-04-09 06:59:50 +02:00
|
|
|
* @deprecated
|
2014-09-25 00:27:17 +02:00
|
|
|
* Returns a JSON-encoded value of the type:
|
2014-09-24 21:55:27 +02:00
|
|
|
* { fileName: string; textSpan: { start: number; length: number}; isWriteAccess: boolean }[]
|
|
|
|
*/
|
2014-07-19 01:55:11 +02:00
|
|
|
getOccurrencesAtPosition(fileName: string, position: number): string;
|
|
|
|
|
2015-04-09 06:59:50 +02:00
|
|
|
/**
|
|
|
|
* Returns a JSON-encoded value of the type:
|
|
|
|
* { fileName: string; highlights: { start: number; length: number, isDefinition: boolean }[] }[]
|
2015-05-05 22:36:59 +02:00
|
|
|
*
|
|
|
|
* @param fileToSearch A JSON encoded string[] containing the file names that should be
|
2015-04-09 08:16:16 +02:00
|
|
|
* considered when searching.
|
2015-04-09 06:59:50 +02:00
|
|
|
*/
|
2015-04-09 08:16:16 +02:00
|
|
|
getDocumentHighlights(fileName: string, position: number, filesToSearch: string): string;
|
2015-04-09 06:59:50 +02:00
|
|
|
|
2014-09-24 21:55:27 +02:00
|
|
|
/**
|
2014-09-25 00:27:17 +02:00
|
|
|
* Returns a JSON-encoded value of the type:
|
2014-09-24 21:55:27 +02:00
|
|
|
* { name: string; kind: string; kindModifiers: string; containerName: string; containerKind: string; matchKind: string; fileName: string; textSpan: { start: number; length: number}; } [] = [];
|
|
|
|
*/
|
2016-09-13 02:17:52 +02:00
|
|
|
getNavigateToItems(searchValue: string, maxResultCount?: number, fileName?: string): string;
|
2014-07-19 01:55:11 +02:00
|
|
|
|
2014-09-24 21:55:27 +02:00
|
|
|
/**
|
2014-09-25 00:27:17 +02:00
|
|
|
* Returns a JSON-encoded value of the type:
|
2014-09-24 21:55:27 +02:00
|
|
|
* { text: string; kind: string; kindModifiers: string; bolded: boolean; grayed: boolean; indent: number; spans: { start: number; length: number; }[]; childItems: <recursive use of this type>[] } [] = [];
|
|
|
|
*/
|
2014-08-15 01:51:16 +02:00
|
|
|
getNavigationBarItems(fileName: string): string;
|
2014-07-19 01:55:11 +02:00
|
|
|
|
2016-10-11 16:48:28 +02:00
|
|
|
/** Returns a JSON-encoded value of the type ts.NavigationTree. */
|
|
|
|
getNavigationTree(fileName: string): string;
|
|
|
|
|
2014-09-24 21:55:27 +02:00
|
|
|
/**
|
2014-09-25 00:27:17 +02:00
|
|
|
* Returns a JSON-encoded value of the type:
|
2014-09-24 21:55:27 +02:00
|
|
|
* { textSpan: { start: number, length: number }; hintSpan: { start: number, length: number }; bannerText: string; autoCollapse: boolean } [] = [];
|
|
|
|
*/
|
2014-08-15 01:51:16 +02:00
|
|
|
getOutliningSpans(fileName: string): string;
|
|
|
|
|
|
|
|
getTodoComments(fileName: string, todoCommentDescriptors: string): string;
|
2014-07-19 01:55:11 +02:00
|
|
|
|
|
|
|
getBraceMatchingAtPosition(fileName: string, position: number): string;
|
|
|
|
getIndentationAtPosition(fileName: string, position: number, options: string/*Services.EditorOptions*/): string;
|
|
|
|
|
2014-08-15 01:51:16 +02:00
|
|
|
getFormattingEditsForRange(fileName: string, start: number, end: number, options: string/*Services.FormatCodeOptions*/): string;
|
|
|
|
getFormattingEditsForDocument(fileName: string, options: string/*Services.FormatCodeOptions*/): string;
|
2014-07-19 01:55:11 +02:00
|
|
|
getFormattingEditsAfterKeystroke(fileName: string, position: number, key: string, options: string/*Services.FormatCodeOptions*/): string;
|
|
|
|
|
2015-07-21 03:31:17 +02:00
|
|
|
/**
|
|
|
|
* Returns JSON-encoded value of the type TextInsertion.
|
|
|
|
*/
|
2021-02-06 00:24:48 +01:00
|
|
|
getDocCommentTemplateAtPosition(fileName: string, position: number, options?: DocCommentTemplateOptions): string;
|
2015-07-14 03:56:38 +02:00
|
|
|
|
2016-04-15 20:38:42 +02:00
|
|
|
/**
|
|
|
|
* Returns JSON-encoded boolean to indicate whether we should support brace location
|
|
|
|
* at the current position.
|
|
|
|
* E.g. we don't want brace completion inside string-literals, comments, etc.
|
|
|
|
*/
|
2016-06-24 02:36:59 +02:00
|
|
|
isValidBraceCompletionAtPosition(fileName: string, position: number, openingBrace: number): string;
|
2016-04-15 20:38:42 +02:00
|
|
|
|
2017-06-09 02:08:07 +02:00
|
|
|
/**
|
2017-06-10 03:02:42 +02:00
|
|
|
* Returns a JSON-encoded TextSpan | undefined indicating the range of the enclosing comment, if it exists.
|
2017-06-09 02:08:07 +02:00
|
|
|
*/
|
2017-06-10 03:02:42 +02:00
|
|
|
getSpanOfEnclosingComment(fileName: string, position: number, onlyMultiLine: boolean): string;
|
2017-06-09 02:08:07 +02:00
|
|
|
|
2019-12-22 22:25:09 +01:00
|
|
|
prepareCallHierarchy(fileName: string, position: number): string;
|
|
|
|
provideCallHierarchyIncomingCalls(fileName: string, position: number): string;
|
|
|
|
provideCallHierarchyOutgoingCalls(fileName: string, position: number): string;
|
2021-06-25 08:06:34 +02:00
|
|
|
provideInlayHints(fileName: string, span: TextSpan, preference: InlayHintsOptions | undefined): string;
|
2014-07-19 01:55:11 +02:00
|
|
|
getEmitOutput(fileName: string): string;
|
2016-07-02 02:35:12 +02:00
|
|
|
getEmitOutputObject(fileName: string): EmitOutput;
|
2020-02-21 02:00:23 +01:00
|
|
|
|
2020-03-03 01:30:42 +01:00
|
|
|
toggleLineComment(fileName: string, textChange: TextRange): string;
|
2020-03-03 02:13:15 +01:00
|
|
|
toggleMultilineComment(fileName: string, textChange: TextRange): string;
|
2020-03-03 01:30:42 +01:00
|
|
|
commentSelection(fileName: string, textChange: TextRange): string;
|
|
|
|
uncommentSelection(fileName: string, textChange: TextRange): string;
|
2014-07-13 01:04:16 +02:00
|
|
|
}
|
|
|
|
|
2014-07-24 21:00:45 +02:00
|
|
|
export interface ClassifierShim extends Shim {
|
2015-05-01 02:39:51 +02:00
|
|
|
getEncodedLexicalClassifications(text: string, lexState: EndOfLineState, syntacticClassifierAbsent?: boolean): string;
|
2015-01-26 21:37:03 +01:00
|
|
|
getClassificationsForLine(text: string, lexState: EndOfLineState, syntacticClassifierAbsent?: boolean): string;
|
2014-07-24 20:57:18 +02:00
|
|
|
}
|
2014-07-19 01:55:11 +02:00
|
|
|
|
2014-07-24 21:00:45 +02:00
|
|
|
export interface CoreServicesShim extends Shim {
|
2016-08-04 16:43:54 +02:00
|
|
|
getAutomaticTypeDirectiveNames(compilerOptionsJson: string): string;
|
2014-11-18 02:01:23 +01:00
|
|
|
getPreProcessedFileInfo(fileName: string, sourceText: IScriptSnapshot): string;
|
2015-04-21 22:24:02 +02:00
|
|
|
getTSConfigFileInfo(fileName: string, sourceText: IScriptSnapshot): string;
|
2014-07-24 20:57:18 +02:00
|
|
|
getDefaultCompilationSettings(): string;
|
2016-03-02 03:52:11 +01:00
|
|
|
discoverTypings(discoverTypingsJson: string): string;
|
2014-07-24 20:57:18 +02:00
|
|
|
}
|
|
|
|
|
2014-07-25 01:01:51 +02:00
|
|
|
function logInternalError(logger: Logger, err: Error) {
|
2015-04-30 23:26:46 +02:00
|
|
|
if (logger) {
|
|
|
|
logger.log("*INTERNAL ERROR* - Exception in typescript services: " + err.message);
|
|
|
|
}
|
2014-07-25 00:58:33 +02:00
|
|
|
}
|
|
|
|
|
2014-11-18 02:01:23 +01:00
|
|
|
class ScriptSnapshotShimAdapter implements IScriptSnapshot {
|
2014-07-25 01:03:48 +02:00
|
|
|
constructor(private scriptSnapshotShim: ScriptSnapshotShim) {
|
2014-07-13 01:04:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public getText(start: number, end: number): string {
|
|
|
|
return this.scriptSnapshotShim.getText(start, end);
|
|
|
|
}
|
|
|
|
|
|
|
|
public getLength(): number {
|
|
|
|
return this.scriptSnapshotShim.getLength();
|
|
|
|
}
|
|
|
|
|
2018-05-22 23:46:57 +02:00
|
|
|
public getChangeRange(oldSnapshot: IScriptSnapshot): TextChangeRange | undefined {
|
2021-05-18 15:20:57 +02:00
|
|
|
const oldSnapshotShim = oldSnapshot as ScriptSnapshotShimAdapter;
|
2016-01-07 18:16:14 +01:00
|
|
|
const encoded = this.scriptSnapshotShim.getChangeRange(oldSnapshotShim.scriptSnapshotShim);
|
2019-07-18 09:50:38 +02:00
|
|
|
/* eslint-disable no-null/no-null */
|
2017-04-05 00:51:13 +02:00
|
|
|
if (encoded === null) {
|
2018-05-22 23:46:57 +02:00
|
|
|
return null!; // TODO: GH#18217
|
2014-07-13 01:04:16 +02:00
|
|
|
}
|
2019-07-18 09:50:38 +02:00
|
|
|
/* eslint-enable no-null/no-null */
|
2014-07-13 01:04:16 +02:00
|
|
|
|
2018-05-22 23:46:57 +02:00
|
|
|
const decoded: { span: { start: number; length: number; }; newLength: number; } = JSON.parse(encoded!); // TODO: GH#18217
|
2014-12-10 23:36:37 +01:00
|
|
|
return createTextChangeRange(
|
2014-12-10 22:45:08 +01:00
|
|
|
createTextSpan(decoded.span.start, decoded.span.length), decoded.newLength);
|
2014-07-13 01:04:16 +02:00
|
|
|
}
|
2015-07-01 01:11:09 +02:00
|
|
|
|
|
|
|
public dispose(): void {
|
2015-07-09 22:13:49 +02:00
|
|
|
// if scriptSnapshotShim is a COM object then property check becomes method call with no arguments
|
|
|
|
// 'in' does not have this effect
|
2015-07-01 01:11:09 +02:00
|
|
|
if ("dispose" in this.scriptSnapshotShim) {
|
2018-05-22 23:46:57 +02:00
|
|
|
this.scriptSnapshotShim.dispose!(); // TODO: GH#18217 Can we just use `if (this.scriptSnapshotShim.dispose)`?
|
2015-07-01 01:11:09 +02:00
|
|
|
}
|
|
|
|
}
|
2014-07-13 01:04:16 +02:00
|
|
|
}
|
|
|
|
|
2014-08-15 02:49:02 +02:00
|
|
|
export class LanguageServiceShimHostAdapter implements LanguageServiceHost {
|
2015-06-12 22:49:38 +02:00
|
|
|
private loggingEnabled = false;
|
|
|
|
private tracingEnabled = false;
|
2015-12-24 09:21:03 +01:00
|
|
|
|
2018-11-17 01:02:23 +01:00
|
|
|
public resolveModuleNames: ((moduleName: string[], containingFile: string) => (ResolvedModuleFull | undefined)[]) | undefined;
|
|
|
|
public resolveTypeReferenceDirectives: ((typeDirectiveNames: string[], containingFile: string) => (ResolvedTypeReferenceDirective | undefined)[]) | undefined;
|
|
|
|
public directoryExists: ((directoryName: string) => boolean) | undefined;
|
2016-01-07 18:24:32 +01:00
|
|
|
|
2014-07-24 21:00:45 +02:00
|
|
|
constructor(private shimHost: LanguageServiceShimHost) {
|
2015-08-03 20:06:23 +02:00
|
|
|
// if shimHost is a COM object then property check will become method call with no arguments.
|
2016-06-03 18:33:17 +02:00
|
|
|
// 'in' does not have this effect.
|
2015-07-14 02:44:50 +02:00
|
|
|
if ("getModuleResolutionsForFile" in this.shimHost) {
|
2018-10-22 21:23:04 +02:00
|
|
|
this.resolveModuleNames = (moduleNames, containingFile) => {
|
2021-05-18 15:20:57 +02:00
|
|
|
const resolutionsInFile = JSON.parse(this.shimHost.getModuleResolutionsForFile!(containingFile)) as MapLike<string>; // TODO: GH#18217
|
2015-09-10 20:36:31 +02:00
|
|
|
return map(moduleNames, name => {
|
2016-08-15 21:03:39 +02:00
|
|
|
const result = getProperty(resolutionsInFile, name);
|
2018-10-22 21:23:04 +02:00
|
|
|
return result ? { resolvedFileName: result, extension: extensionFromPath(result), isExternalLibraryImport: false } : undefined;
|
2015-09-10 20:36:31 +02:00
|
|
|
});
|
2015-07-14 02:44:50 +02:00
|
|
|
};
|
|
|
|
}
|
2016-01-06 21:37:52 +01:00
|
|
|
if ("directoryExists" in this.shimHost) {
|
|
|
|
this.directoryExists = directoryName => this.shimHost.directoryExists(directoryName);
|
|
|
|
}
|
2016-04-01 21:41:01 +02:00
|
|
|
if ("getTypeReferenceDirectiveResolutionsForFile" in this.shimHost) {
|
2018-10-22 21:23:04 +02:00
|
|
|
this.resolveTypeReferenceDirectives = (typeDirectiveNames, containingFile) => {
|
2021-05-18 15:20:57 +02:00
|
|
|
const typeDirectivesForFile = JSON.parse(this.shimHost.getTypeReferenceDirectiveResolutionsForFile!(containingFile)) as MapLike<ResolvedTypeReferenceDirective>; // TODO: GH#18217
|
2018-10-22 21:23:04 +02:00
|
|
|
return map(typeDirectiveNames, name => getProperty(typeDirectivesForFile, name));
|
2016-04-01 21:41:01 +02:00
|
|
|
};
|
|
|
|
}
|
2014-07-19 01:55:11 +02:00
|
|
|
}
|
|
|
|
|
2014-07-13 01:04:16 +02:00
|
|
|
public log(s: string): void {
|
2015-06-12 22:49:38 +02:00
|
|
|
if (this.loggingEnabled) {
|
|
|
|
this.shimHost.log(s);
|
|
|
|
}
|
2014-07-13 01:04:16 +02:00
|
|
|
}
|
|
|
|
|
2014-12-07 06:23:54 +01:00
|
|
|
public trace(s: string): void {
|
2015-06-12 22:49:38 +02:00
|
|
|
if (this.tracingEnabled) {
|
|
|
|
this.shimHost.trace(s);
|
|
|
|
}
|
2014-12-07 06:23:54 +01:00
|
|
|
}
|
2015-05-05 22:36:59 +02:00
|
|
|
|
2014-12-07 06:23:54 +01:00
|
|
|
public error(s: string): void {
|
|
|
|
this.shimHost.error(s);
|
2015-07-30 03:14:13 +02:00
|
|
|
}
|
2014-12-07 06:23:54 +01:00
|
|
|
|
2015-05-12 19:57:55 +02:00
|
|
|
public getProjectVersion(): string {
|
|
|
|
if (!this.shimHost.getProjectVersion) {
|
|
|
|
// shimmed host does not support getProjectVersion
|
2018-05-22 23:46:57 +02:00
|
|
|
return undefined!; // TODO: GH#18217
|
2015-05-12 19:57:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return this.shimHost.getProjectVersion();
|
|
|
|
}
|
|
|
|
|
2016-09-20 01:47:15 +02:00
|
|
|
public getTypeRootsVersion(): number {
|
2016-09-20 02:53:10 +02:00
|
|
|
if (!this.shimHost.getTypeRootsVersion) {
|
|
|
|
return 0;
|
|
|
|
}
|
2016-09-20 01:47:15 +02:00
|
|
|
return this.shimHost.getTypeRootsVersion();
|
|
|
|
}
|
|
|
|
|
2015-06-03 22:48:34 +02:00
|
|
|
public useCaseSensitiveFileNames(): boolean {
|
2015-06-04 00:22:17 +02:00
|
|
|
return this.shimHost.useCaseSensitiveFileNames ? this.shimHost.useCaseSensitiveFileNames() : false;
|
2015-06-03 22:48:34 +02:00
|
|
|
}
|
|
|
|
|
2014-07-25 21:18:12 +02:00
|
|
|
public getCompilationSettings(): CompilerOptions {
|
2016-01-07 18:16:14 +01:00
|
|
|
const settingsJson = this.shimHost.getCompilationSettings();
|
2019-07-18 09:50:38 +02:00
|
|
|
// eslint-disable-next-line no-null/no-null
|
2017-04-05 00:51:13 +02:00
|
|
|
if (settingsJson === null || settingsJson === "") {
|
2014-07-19 01:55:11 +02:00
|
|
|
throw Error("LanguageServiceShimHostAdapter.getCompilationSettings: empty compilationSettings");
|
2014-07-13 01:04:16 +02:00
|
|
|
}
|
2021-05-18 15:20:57 +02:00
|
|
|
const compilerOptions = JSON.parse(settingsJson) as CompilerOptions;
|
2017-01-30 22:19:44 +01:00
|
|
|
// permit language service to handle all files (filtering should be performed on the host side)
|
|
|
|
compilerOptions.allowNonTsExtensions = true;
|
|
|
|
return compilerOptions;
|
2014-07-13 01:04:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public getScriptFileNames(): string[] {
|
2016-01-07 18:16:14 +01:00
|
|
|
const encoded = this.shimHost.getScriptFileNames();
|
2018-08-13 20:14:52 +02:00
|
|
|
return JSON.parse(encoded);
|
2014-07-13 01:04:16 +02:00
|
|
|
}
|
|
|
|
|
2018-05-22 23:46:57 +02:00
|
|
|
public getScriptSnapshot(fileName: string): IScriptSnapshot | undefined {
|
2016-01-07 18:16:14 +01:00
|
|
|
const scriptSnapshot = this.shimHost.getScriptSnapshot(fileName);
|
2015-01-28 09:08:05 +01:00
|
|
|
return scriptSnapshot && new ScriptSnapshotShimAdapter(scriptSnapshot);
|
2014-07-13 01:04:16 +02:00
|
|
|
}
|
|
|
|
|
2016-02-17 02:37:24 +01:00
|
|
|
public getScriptKind(fileName: string): ScriptKind {
|
2016-02-18 04:07:19 +01:00
|
|
|
if ("getScriptKind" in this.shimHost) {
|
2018-05-22 23:46:57 +02:00
|
|
|
return this.shimHost.getScriptKind!(fileName); // TODO: GH#18217
|
2016-02-17 07:44:43 +01:00
|
|
|
}
|
2016-02-18 04:07:19 +01:00
|
|
|
else {
|
2016-02-17 02:37:24 +01:00
|
|
|
return ScriptKind.Unknown;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-15 02:49:02 +02:00
|
|
|
public getScriptVersion(fileName: string): string {
|
2014-07-13 01:04:16 +02:00
|
|
|
return this.shimHost.getScriptVersion(fileName);
|
|
|
|
}
|
|
|
|
|
2017-10-10 19:54:29 +02:00
|
|
|
public getLocalizedDiagnosticMessages() {
|
2019-07-18 09:50:38 +02:00
|
|
|
/* eslint-disable no-null/no-null */
|
2016-01-07 18:16:14 +01:00
|
|
|
const diagnosticMessagesJson = this.shimHost.getLocalizedDiagnosticMessages();
|
2017-04-05 00:51:13 +02:00
|
|
|
if (diagnosticMessagesJson === null || diagnosticMessagesJson === "") {
|
2014-07-13 01:04:16 +02:00
|
|
|
return null;
|
|
|
|
}
|
2014-10-03 02:58:05 +02:00
|
|
|
|
2014-07-13 01:04:16 +02:00
|
|
|
try {
|
|
|
|
return JSON.parse(diagnosticMessagesJson);
|
|
|
|
}
|
|
|
|
catch (e) {
|
|
|
|
this.log(e.description || "diagnosticMessages.generated.json has invalid JSON format");
|
|
|
|
return null;
|
|
|
|
}
|
2019-07-18 09:50:38 +02:00
|
|
|
/* eslint-enable no-null/no-null */
|
2014-07-13 01:04:16 +02:00
|
|
|
}
|
|
|
|
|
2015-06-18 21:04:26 +02:00
|
|
|
public getCancellationToken(): HostCancellationToken {
|
2016-01-07 18:16:14 +01:00
|
|
|
const hostCancellationToken = this.shimHost.getCancellationToken();
|
2015-07-06 23:04:42 +02:00
|
|
|
return new ThrottledCancellationToken(hostCancellationToken);
|
2014-07-19 01:55:11 +02:00
|
|
|
}
|
2014-09-16 22:19:49 +02:00
|
|
|
|
|
|
|
public getCurrentDirectory(): string {
|
|
|
|
return this.shimHost.getCurrentDirectory();
|
|
|
|
}
|
2015-01-28 09:08:05 +01:00
|
|
|
|
2016-05-24 20:10:57 +02:00
|
|
|
public getDirectories(path: string): string[] {
|
2016-07-08 01:10:20 +02:00
|
|
|
return JSON.parse(this.shimHost.getDirectories(path));
|
2016-05-24 20:10:57 +02:00
|
|
|
}
|
|
|
|
|
2015-02-04 01:08:46 +01:00
|
|
|
public getDefaultLibFileName(options: CompilerOptions): string {
|
2015-12-24 09:18:10 +01:00
|
|
|
return this.shimHost.getDefaultLibFileName(JSON.stringify(options));
|
2015-01-28 09:08:05 +01:00
|
|
|
}
|
2016-06-24 22:56:45 +02:00
|
|
|
|
2019-08-08 20:30:18 +02:00
|
|
|
public readDirectory(path: string, extensions?: readonly string[], exclude?: string[], include?: string[], depth?: number): string[] {
|
2016-10-10 22:06:58 +02:00
|
|
|
const pattern = getFileMatcherPatterns(path, exclude, include,
|
2018-05-22 23:46:57 +02:00
|
|
|
this.shimHost.useCaseSensitiveFileNames!(), this.shimHost.getCurrentDirectory()); // TODO: GH#18217
|
2016-06-24 22:56:45 +02:00
|
|
|
return JSON.parse(this.shimHost.readDirectory(
|
|
|
|
path,
|
2016-08-04 20:10:00 +02:00
|
|
|
JSON.stringify(extensions),
|
|
|
|
JSON.stringify(pattern.basePaths),
|
|
|
|
pattern.excludePattern,
|
|
|
|
pattern.includeFilePattern,
|
|
|
|
pattern.includeDirectoryPattern,
|
|
|
|
depth
|
2016-06-24 22:56:45 +02:00
|
|
|
));
|
|
|
|
}
|
|
|
|
|
2017-07-14 23:26:13 +02:00
|
|
|
public readFile(path: string, encoding?: string): string | undefined {
|
2016-06-24 22:56:45 +02:00
|
|
|
return this.shimHost.readFile(path, encoding);
|
|
|
|
}
|
|
|
|
|
|
|
|
public fileExists(path: string): boolean {
|
|
|
|
return this.shimHost.fileExists(path);
|
|
|
|
}
|
2014-07-19 01:55:11 +02:00
|
|
|
}
|
2015-05-05 22:36:59 +02:00
|
|
|
|
2017-06-29 20:04:33 +02:00
|
|
|
export class CoreServicesShimHostAdapter implements ParseConfigHost, ModuleResolutionHost, JsTyping.TypingResolutionHost {
|
2015-04-21 22:24:02 +02:00
|
|
|
|
2016-01-06 21:37:52 +01:00
|
|
|
public directoryExists: (directoryName: string) => boolean;
|
2016-05-05 22:38:09 +02:00
|
|
|
public realpath: (path: string) => string;
|
2016-05-26 02:07:36 +02:00
|
|
|
public useCaseSensitiveFileNames: boolean;
|
2016-01-07 18:24:32 +01:00
|
|
|
|
2015-04-21 22:24:02 +02:00
|
|
|
constructor(private shimHost: CoreServicesShimHost) {
|
2018-11-17 01:02:23 +01:00
|
|
|
this.useCaseSensitiveFileNames = this.shimHost.useCaseSensitiveFileNames ? this.shimHost.useCaseSensitiveFileNames() : false;
|
2016-01-06 21:37:52 +01:00
|
|
|
if ("directoryExists" in this.shimHost) {
|
|
|
|
this.directoryExists = directoryName => this.shimHost.directoryExists(directoryName);
|
|
|
|
}
|
2018-11-17 01:02:23 +01:00
|
|
|
else {
|
|
|
|
this.directoryExists = undefined!; // TODO: GH#18217
|
|
|
|
}
|
2016-05-05 22:38:09 +02:00
|
|
|
if ("realpath" in this.shimHost) {
|
2018-05-22 23:46:57 +02:00
|
|
|
this.realpath = path => this.shimHost.realpath!(path); // TODO: GH#18217
|
2016-05-05 22:38:09 +02:00
|
|
|
}
|
2018-11-17 01:02:23 +01:00
|
|
|
else {
|
|
|
|
this.realpath = undefined!; // TODO: GH#18217
|
|
|
|
}
|
2015-04-21 22:24:02 +02:00
|
|
|
}
|
|
|
|
|
2019-08-08 20:30:18 +02:00
|
|
|
public readDirectory(rootDir: string, extensions: readonly string[], exclude: readonly string[], include: readonly string[], depth?: number): string[] {
|
2017-06-29 20:04:33 +02:00
|
|
|
const pattern = getFileMatcherPatterns(rootDir, exclude, include,
|
2018-05-22 23:46:57 +02:00
|
|
|
this.shimHost.useCaseSensitiveFileNames!(), this.shimHost.getCurrentDirectory()); // TODO: GH#18217
|
2017-06-29 20:04:33 +02:00
|
|
|
return JSON.parse(this.shimHost.readDirectory(
|
|
|
|
rootDir,
|
|
|
|
JSON.stringify(extensions),
|
|
|
|
JSON.stringify(pattern.basePaths),
|
|
|
|
pattern.excludePattern,
|
|
|
|
pattern.includeFilePattern,
|
|
|
|
pattern.includeDirectoryPattern,
|
|
|
|
depth
|
|
|
|
));
|
2015-04-21 22:24:02 +02:00
|
|
|
}
|
2015-12-24 09:21:03 +01:00
|
|
|
|
2015-07-14 02:44:50 +02:00
|
|
|
public fileExists(fileName: string): boolean {
|
|
|
|
return this.shimHost.fileExists(fileName);
|
|
|
|
}
|
2015-12-24 09:21:03 +01:00
|
|
|
|
2017-07-14 23:26:13 +02:00
|
|
|
public readFile(fileName: string): string | undefined {
|
2015-08-05 06:22:37 +02:00
|
|
|
return this.shimHost.readFile(fileName);
|
|
|
|
}
|
2015-12-15 00:21:12 +01:00
|
|
|
|
2016-08-04 16:43:54 +02:00
|
|
|
public getDirectories(path: string): string[] {
|
|
|
|
return JSON.parse(this.shimHost.getDirectories(path));
|
|
|
|
}
|
2015-04-21 22:24:02 +02:00
|
|
|
}
|
2014-07-19 01:55:11 +02:00
|
|
|
|
2017-10-10 19:54:29 +02:00
|
|
|
function simpleForwardCall(logger: Logger, actionDescription: string, action: () => {}, logPerformance: boolean): {} {
|
2018-05-22 23:46:57 +02:00
|
|
|
let start: number | undefined;
|
2015-06-12 22:49:38 +02:00
|
|
|
if (logPerformance) {
|
2015-04-30 23:26:46 +02:00
|
|
|
logger.log(actionDescription);
|
2016-07-21 00:42:29 +02:00
|
|
|
start = timestamp();
|
2015-04-30 23:26:46 +02:00
|
|
|
}
|
|
|
|
|
2016-01-07 18:16:14 +01:00
|
|
|
const result = action();
|
2015-04-30 23:26:46 +02:00
|
|
|
|
2015-06-12 22:49:38 +02:00
|
|
|
if (logPerformance) {
|
2016-07-21 00:42:29 +02:00
|
|
|
const end = timestamp();
|
2019-06-24 13:55:58 +02:00
|
|
|
logger.log(`${actionDescription} completed in ${end - start!} msec`);
|
2017-07-19 22:07:55 +02:00
|
|
|
if (isString(result)) {
|
2015-12-24 09:21:03 +01:00
|
|
|
let str = result;
|
2015-04-30 23:26:46 +02:00
|
|
|
if (str.length > 128) {
|
|
|
|
str = str.substring(0, 128) + "...";
|
|
|
|
}
|
2015-12-24 09:21:03 +01:00
|
|
|
logger.log(` result.length=${str.length}, result='${JSON.stringify(str)}'`);
|
2014-07-19 01:55:11 +02:00
|
|
|
}
|
|
|
|
}
|
2015-04-30 23:26:46 +02:00
|
|
|
|
2014-07-19 01:55:11 +02:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2018-05-22 23:46:57 +02:00
|
|
|
function forwardJSONCall(logger: Logger, actionDescription: string, action: () => {} | null | undefined, logPerformance: boolean): string {
|
2021-05-18 15:20:57 +02:00
|
|
|
return forwardCall(logger, actionDescription, /*returnJson*/ true, action, logPerformance) as string;
|
2016-07-02 02:35:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function forwardCall<T>(logger: Logger, actionDescription: string, returnJson: boolean, action: () => T, logPerformance: boolean): T | string {
|
2014-07-19 01:55:11 +02:00
|
|
|
try {
|
2016-01-07 18:16:14 +01:00
|
|
|
const result = simpleForwardCall(logger, actionDescription, action, logPerformance);
|
2017-10-10 19:54:29 +02:00
|
|
|
return returnJson ? JSON.stringify({ result }) : result as T;
|
2014-07-19 01:55:11 +02:00
|
|
|
}
|
|
|
|
catch (err) {
|
|
|
|
if (err instanceof OperationCanceledException) {
|
|
|
|
return JSON.stringify({ canceled: true });
|
|
|
|
}
|
2014-07-24 20:57:18 +02:00
|
|
|
logInternalError(logger, err);
|
2014-07-19 01:55:11 +02:00
|
|
|
err.description = actionDescription;
|
|
|
|
return JSON.stringify({ error: err });
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-02 02:35:12 +02:00
|
|
|
|
2014-07-24 21:00:45 +02:00
|
|
|
class ShimBase implements Shim {
|
|
|
|
constructor(private factory: ShimFactory) {
|
2014-07-24 20:57:18 +02:00
|
|
|
factory.registerShim(this);
|
|
|
|
}
|
2017-10-10 19:54:29 +02:00
|
|
|
public dispose(_dummy: {}): void {
|
2014-07-24 20:57:18 +02:00
|
|
|
this.factory.unregisterShim(this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-26 23:55:26 +01:00
|
|
|
export interface RealizedDiagnostic {
|
2017-09-23 01:14:41 +02:00
|
|
|
message: string;
|
|
|
|
start: number;
|
|
|
|
length: number;
|
|
|
|
category: string;
|
|
|
|
code: number;
|
2018-05-22 16:56:29 +02:00
|
|
|
reportsUnnecessary?: {};
|
2020-06-19 02:41:26 +02:00
|
|
|
reportsDeprecated?: {};
|
2017-09-23 01:14:41 +02:00
|
|
|
}
|
2019-08-08 20:30:18 +02:00
|
|
|
export function realizeDiagnostics(diagnostics: readonly Diagnostic[], newLine: string): RealizedDiagnostic[] {
|
2015-03-18 00:27:56 +01:00
|
|
|
return diagnostics.map(d => realizeDiagnostic(d, newLine));
|
|
|
|
}
|
|
|
|
|
2017-09-23 01:14:41 +02:00
|
|
|
function realizeDiagnostic(diagnostic: Diagnostic, newLine: string): RealizedDiagnostic {
|
2015-03-18 00:27:56 +01:00
|
|
|
return {
|
|
|
|
message: flattenDiagnosticMessageText(diagnostic.messageText, newLine),
|
2018-05-22 23:46:57 +02:00
|
|
|
start: diagnostic.start!, // TODO: GH#18217
|
|
|
|
length: diagnostic.length!, // TODO: GH#18217
|
2018-02-28 20:16:32 +01:00
|
|
|
category: diagnosticCategoryName(diagnostic),
|
2018-05-22 16:56:29 +02:00
|
|
|
code: diagnostic.code,
|
|
|
|
reportsUnnecessary: diagnostic.reportsUnnecessary,
|
2020-06-19 02:41:26 +02:00
|
|
|
reportsDeprecated: diagnostic.reportsDeprecated
|
2015-03-18 00:27:56 +01:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2014-07-24 21:00:45 +02:00
|
|
|
class LanguageServiceShimObject extends ShimBase implements LanguageServiceShim {
|
2014-07-25 01:01:51 +02:00
|
|
|
private logger: Logger;
|
2015-06-12 22:49:38 +02:00
|
|
|
private logPerformance = false;
|
2014-07-19 01:55:11 +02:00
|
|
|
|
2014-07-24 21:00:45 +02:00
|
|
|
constructor(factory: ShimFactory,
|
|
|
|
private host: LanguageServiceShimHost,
|
2014-07-24 20:57:18 +02:00
|
|
|
public languageService: LanguageService) {
|
2014-07-19 01:55:11 +02:00
|
|
|
super(factory);
|
|
|
|
this.logger = this.host;
|
|
|
|
}
|
|
|
|
|
2018-05-22 23:46:57 +02:00
|
|
|
public forwardJSONCall(actionDescription: string, action: () => {} | null | undefined): string {
|
2015-06-12 22:49:38 +02:00
|
|
|
return forwardJSONCall(this.logger, actionDescription, action, this.logPerformance);
|
2014-07-19 01:55:11 +02:00
|
|
|
}
|
|
|
|
|
2014-09-24 21:55:27 +02:00
|
|
|
/// DISPOSE
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Ensure (almost) deterministic release of internal Javascript resources when
|
|
|
|
* some external native objects holds onto us (e.g. Com/Interop).
|
|
|
|
*/
|
2017-10-10 19:54:29 +02:00
|
|
|
public dispose(dummy: {}): void {
|
2014-07-19 01:55:11 +02:00
|
|
|
this.logger.log("dispose()");
|
|
|
|
this.languageService.dispose();
|
2019-07-18 09:50:38 +02:00
|
|
|
this.languageService = null!; // eslint-disable-line no-null/no-null
|
2014-07-19 01:55:11 +02:00
|
|
|
|
|
|
|
// force a GC
|
|
|
|
if (debugObjectHost && debugObjectHost.CollectGarbage) {
|
|
|
|
debugObjectHost.CollectGarbage();
|
|
|
|
this.logger.log("CollectGarbage()");
|
|
|
|
}
|
|
|
|
|
2019-07-18 09:50:38 +02:00
|
|
|
this.logger = null!; // eslint-disable-line no-null/no-null
|
2014-07-19 01:55:11 +02:00
|
|
|
|
|
|
|
super.dispose(dummy);
|
|
|
|
}
|
|
|
|
|
2014-09-24 21:55:27 +02:00
|
|
|
/// REFRESH
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Update the list of scripts known to the compiler
|
|
|
|
*/
|
2014-07-19 01:55:11 +02:00
|
|
|
public refresh(throwOnError: boolean): void {
|
|
|
|
this.forwardJSONCall(
|
2015-12-24 09:21:03 +01:00
|
|
|
`refresh(${throwOnError})`,
|
2019-07-18 09:50:38 +02:00
|
|
|
() => null // eslint-disable-line no-null/no-null
|
2016-01-07 18:24:32 +01:00
|
|
|
);
|
2014-07-19 01:55:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public cleanupSemanticCache(): void {
|
|
|
|
this.forwardJSONCall(
|
|
|
|
"cleanupSemanticCache()",
|
|
|
|
() => {
|
|
|
|
this.languageService.cleanupSemanticCache();
|
2019-07-18 09:50:38 +02:00
|
|
|
return null; // eslint-disable-line no-null/no-null
|
2014-07-19 01:55:11 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-08-08 20:30:18 +02:00
|
|
|
private realizeDiagnostics(diagnostics: readonly Diagnostic[]): { message: string; start: number; length: number; category: string; }[] {
|
2016-01-07 18:16:14 +01:00
|
|
|
const newLine = getNewLineOrDefaultFromHost(this.host);
|
2018-03-01 23:20:18 +01:00
|
|
|
return realizeDiagnostics(diagnostics, newLine);
|
2015-08-05 00:27:16 +02:00
|
|
|
}
|
2014-07-19 01:55:11 +02:00
|
|
|
|
2014-09-13 02:19:48 +02:00
|
|
|
public getSyntacticClassifications(fileName: string, start: number, length: number): string {
|
|
|
|
return this.forwardJSONCall(
|
2015-12-24 09:21:03 +01:00
|
|
|
`getSyntacticClassifications('${fileName}', ${start}, ${length})`,
|
2016-01-07 18:24:32 +01:00
|
|
|
() => this.languageService.getSyntacticClassifications(fileName, createTextSpan(start, length))
|
|
|
|
);
|
2014-09-13 02:19:48 +02:00
|
|
|
}
|
|
|
|
|
2014-09-13 03:28:54 +02:00
|
|
|
public getSemanticClassifications(fileName: string, start: number, length: number): string {
|
|
|
|
return this.forwardJSONCall(
|
2015-12-24 09:21:03 +01:00
|
|
|
`getSemanticClassifications('${fileName}', ${start}, ${length})`,
|
2016-01-07 18:24:32 +01:00
|
|
|
() => this.languageService.getSemanticClassifications(fileName, createTextSpan(start, length))
|
|
|
|
);
|
2014-09-13 03:28:54 +02:00
|
|
|
}
|
|
|
|
|
2015-05-01 02:39:51 +02:00
|
|
|
public getEncodedSyntacticClassifications(fileName: string, start: number, length: number): string {
|
2015-04-23 22:40:34 +02:00
|
|
|
return this.forwardJSONCall(
|
2015-12-24 09:21:03 +01:00
|
|
|
`getEncodedSyntacticClassifications('${fileName}', ${start}, ${length})`,
|
2016-01-07 18:24:32 +01:00
|
|
|
// directly serialize the spans out to a string. This is much faster to decode
|
|
|
|
// on the managed side versus a full JSON array.
|
|
|
|
() => convertClassifications(this.languageService.getEncodedSyntacticClassifications(fileName, createTextSpan(start, length)))
|
|
|
|
);
|
2015-04-23 22:40:34 +02:00
|
|
|
}
|
|
|
|
|
2015-05-01 02:39:51 +02:00
|
|
|
public getEncodedSemanticClassifications(fileName: string, start: number, length: number): string {
|
2015-04-23 22:40:34 +02:00
|
|
|
return this.forwardJSONCall(
|
2015-12-24 09:21:03 +01:00
|
|
|
`getEncodedSemanticClassifications('${fileName}', ${start}, ${length})`,
|
2016-01-07 18:24:32 +01:00
|
|
|
// directly serialize the spans out to a string. This is much faster to decode
|
|
|
|
// on the managed side versus a full JSON array.
|
|
|
|
() => convertClassifications(this.languageService.getEncodedSemanticClassifications(fileName, createTextSpan(start, length)))
|
|
|
|
);
|
2015-04-23 22:40:34 +02:00
|
|
|
}
|
|
|
|
|
2014-07-19 01:55:11 +02:00
|
|
|
public getSyntacticDiagnostics(fileName: string): string {
|
|
|
|
return this.forwardJSONCall(
|
2015-12-24 09:21:03 +01:00
|
|
|
`getSyntacticDiagnostics('${fileName}')`,
|
2014-07-19 01:55:11 +02:00
|
|
|
() => {
|
2016-01-07 18:24:32 +01:00
|
|
|
const diagnostics = this.languageService.getSyntacticDiagnostics(fileName);
|
2015-02-05 11:10:36 +01:00
|
|
|
return this.realizeDiagnostics(diagnostics);
|
2014-07-19 01:55:11 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
public getSemanticDiagnostics(fileName: string): string {
|
|
|
|
return this.forwardJSONCall(
|
2015-12-24 09:21:03 +01:00
|
|
|
`getSemanticDiagnostics('${fileName}')`,
|
2014-07-19 01:55:11 +02:00
|
|
|
() => {
|
2016-01-07 18:24:32 +01:00
|
|
|
const diagnostics = this.languageService.getSemanticDiagnostics(fileName);
|
2015-02-05 11:10:36 +01:00
|
|
|
return this.realizeDiagnostics(diagnostics);
|
2014-07-19 01:55:11 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-02-28 20:16:32 +01:00
|
|
|
public getSuggestionDiagnostics(fileName: string): string {
|
|
|
|
return this.forwardJSONCall(`getSuggestionDiagnostics('${fileName}')`, () => this.realizeDiagnostics(this.languageService.getSuggestionDiagnostics(fileName)));
|
|
|
|
}
|
|
|
|
|
2014-07-19 01:55:11 +02:00
|
|
|
public getCompilerOptionsDiagnostics(): string {
|
|
|
|
return this.forwardJSONCall(
|
|
|
|
"getCompilerOptionsDiagnostics()",
|
|
|
|
() => {
|
2016-01-07 18:24:32 +01:00
|
|
|
const diagnostics = this.languageService.getCompilerOptionsDiagnostics();
|
2015-02-05 11:10:36 +01:00
|
|
|
return this.realizeDiagnostics(diagnostics);
|
2014-07-19 01:55:11 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/// QUICKINFO
|
2014-09-24 21:55:27 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Computes a string representation of the type at the requested position
|
|
|
|
* in the active file.
|
|
|
|
*/
|
2014-09-20 00:32:27 +02:00
|
|
|
public getQuickInfoAtPosition(fileName: string, position: number): string {
|
|
|
|
return this.forwardJSONCall(
|
2015-12-24 09:21:03 +01:00
|
|
|
`getQuickInfoAtPosition('${fileName}', ${position})`,
|
2016-01-07 18:24:32 +01:00
|
|
|
() => this.languageService.getQuickInfoAtPosition(fileName, position)
|
|
|
|
);
|
2014-09-20 00:32:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-07-19 01:55:11 +02:00
|
|
|
/// NAMEORDOTTEDNAMESPAN
|
2014-09-24 21:55:27 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Computes span information of the name or dotted name at the requested position
|
|
|
|
* in the active file.
|
|
|
|
*/
|
2014-07-19 01:55:11 +02:00
|
|
|
public getNameOrDottedNameSpan(fileName: string, startPos: number, endPos: number): string {
|
|
|
|
return this.forwardJSONCall(
|
2015-12-24 09:21:03 +01:00
|
|
|
`getNameOrDottedNameSpan('${fileName}', ${startPos}, ${endPos})`,
|
2016-01-07 18:24:32 +01:00
|
|
|
() => this.languageService.getNameOrDottedNameSpan(fileName, startPos, endPos)
|
|
|
|
);
|
2014-07-19 01:55:11 +02:00
|
|
|
}
|
|
|
|
|
2014-09-24 21:55:27 +02:00
|
|
|
/**
|
|
|
|
* STATEMENTSPAN
|
|
|
|
* Computes span information of statement at the requested position in the active file.
|
|
|
|
*/
|
2014-07-19 01:55:11 +02:00
|
|
|
public getBreakpointStatementAtPosition(fileName: string, position: number): string {
|
|
|
|
return this.forwardJSONCall(
|
2015-12-24 09:21:03 +01:00
|
|
|
`getBreakpointStatementAtPosition('${fileName}', ${position})`,
|
2016-01-07 18:24:32 +01:00
|
|
|
() => this.languageService.getBreakpointStatementAtPosition(fileName, position)
|
|
|
|
);
|
2014-07-19 01:55:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/// SIGNATUREHELP
|
2014-08-15 01:51:16 +02:00
|
|
|
|
2018-06-13 00:36:53 +02:00
|
|
|
public getSignatureHelpItems(fileName: string, position: number, options: SignatureHelpItemsOptions | undefined): string {
|
2014-07-19 01:55:11 +02:00
|
|
|
return this.forwardJSONCall(
|
2015-12-24 09:21:03 +01:00
|
|
|
`getSignatureHelpItems('${fileName}', ${position})`,
|
2018-06-13 00:36:53 +02:00
|
|
|
() => this.languageService.getSignatureHelpItems(fileName, position, options)
|
2016-01-07 18:24:32 +01:00
|
|
|
);
|
2014-07-19 01:55:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/// GOTO DEFINITION
|
2014-09-24 21:55:27 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Computes the definition location and file for the symbol
|
2015-05-05 22:36:59 +02:00
|
|
|
* at the requested position.
|
2014-09-24 21:55:27 +02:00
|
|
|
*/
|
2014-07-19 01:55:11 +02:00
|
|
|
public getDefinitionAtPosition(fileName: string, position: number): string {
|
|
|
|
return this.forwardJSONCall(
|
2015-12-24 09:21:03 +01:00
|
|
|
`getDefinitionAtPosition('${fileName}', ${position})`,
|
2016-01-07 18:24:32 +01:00
|
|
|
() => this.languageService.getDefinitionAtPosition(fileName, position)
|
|
|
|
);
|
2017-10-18 23:48:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Computes the definition location and file for the symbol
|
|
|
|
* at the requested position.
|
|
|
|
*/
|
|
|
|
public getDefinitionAndBoundSpan(fileName: string, position: number): string {
|
|
|
|
return this.forwardJSONCall(
|
|
|
|
`getDefinitionAndBoundSpan('${fileName}', ${position})`,
|
|
|
|
() => this.languageService.getDefinitionAndBoundSpan(fileName, position)
|
|
|
|
);
|
2014-07-19 01:55:11 +02:00
|
|
|
}
|
|
|
|
|
2015-04-30 07:06:24 +02:00
|
|
|
/// GOTO Type
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Computes the definition location of the type of the symbol
|
2015-05-05 22:36:59 +02:00
|
|
|
* at the requested position.
|
2015-04-30 07:06:24 +02:00
|
|
|
*/
|
|
|
|
public getTypeDefinitionAtPosition(fileName: string, position: number): string {
|
|
|
|
return this.forwardJSONCall(
|
2015-12-24 09:21:03 +01:00
|
|
|
`getTypeDefinitionAtPosition('${fileName}', ${position})`,
|
2016-01-07 18:24:32 +01:00
|
|
|
() => this.languageService.getTypeDefinitionAtPosition(fileName, position)
|
|
|
|
);
|
2015-04-30 07:06:24 +02:00
|
|
|
}
|
|
|
|
|
2016-08-22 22:57:40 +02:00
|
|
|
/// GOTO Implementation
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Computes the implementation location of the symbol
|
|
|
|
* at the requested position.
|
|
|
|
*/
|
|
|
|
public getImplementationAtPosition(fileName: string, position: number): string {
|
|
|
|
return this.forwardJSONCall(
|
|
|
|
`getImplementationAtPosition('${fileName}', ${position})`,
|
|
|
|
() => this.languageService.getImplementationAtPosition(fileName, position)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-01-11 23:45:08 +01:00
|
|
|
public getRenameInfo(fileName: string, position: number, options?: RenameInfoOptions): string {
|
2014-08-15 01:51:16 +02:00
|
|
|
return this.forwardJSONCall(
|
2015-12-24 09:21:03 +01:00
|
|
|
`getRenameInfo('${fileName}', ${position})`,
|
2019-01-11 23:45:08 +01:00
|
|
|
() => this.languageService.getRenameInfo(fileName, position, options)
|
2016-01-07 18:24:32 +01:00
|
|
|
);
|
2014-08-15 01:51:16 +02:00
|
|
|
}
|
|
|
|
|
2019-04-19 01:23:06 +02:00
|
|
|
public getSmartSelectionRange(fileName: string, position: number): string {
|
2019-04-12 02:32:40 +02:00
|
|
|
return this.forwardJSONCall(
|
2019-04-19 01:23:06 +02:00
|
|
|
`getSmartSelectionRange('${fileName}', ${position})`,
|
|
|
|
() => this.languageService.getSmartSelectionRange(fileName, position)
|
2019-04-12 02:32:40 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-01-16 19:58:07 +01:00
|
|
|
public findRenameLocations(fileName: string, position: number, findInStrings: boolean, findInComments: boolean, providePrefixAndSuffixTextForRename?: boolean): string {
|
2014-10-03 23:53:50 +02:00
|
|
|
return this.forwardJSONCall(
|
2019-01-16 19:58:07 +01:00
|
|
|
`findRenameLocations('${fileName}', ${position}, ${findInStrings}, ${findInComments}, ${providePrefixAndSuffixTextForRename})`,
|
|
|
|
() => this.languageService.findRenameLocations(fileName, position, findInStrings, findInComments, providePrefixAndSuffixTextForRename)
|
2016-01-07 18:24:32 +01:00
|
|
|
);
|
2014-10-03 23:53:50 +02:00
|
|
|
}
|
|
|
|
|
2014-07-19 01:55:11 +02:00
|
|
|
/// GET BRACE MATCHING
|
|
|
|
public getBraceMatchingAtPosition(fileName: string, position: number): string {
|
|
|
|
return this.forwardJSONCall(
|
2015-12-24 09:21:03 +01:00
|
|
|
`getBraceMatchingAtPosition('${fileName}', ${position})`,
|
2016-01-07 18:24:32 +01:00
|
|
|
() => this.languageService.getBraceMatchingAtPosition(fileName, position)
|
|
|
|
);
|
2014-07-19 01:55:11 +02:00
|
|
|
}
|
|
|
|
|
2016-06-24 02:36:59 +02:00
|
|
|
public isValidBraceCompletionAtPosition(fileName: string, position: number, openingBrace: number): string {
|
2016-04-15 20:38:42 +02:00
|
|
|
return this.forwardJSONCall(
|
2016-06-24 02:36:59 +02:00
|
|
|
`isValidBraceCompletionAtPosition('${fileName}', ${position}, ${openingBrace})`,
|
|
|
|
() => this.languageService.isValidBraceCompletionAtPosition(fileName, position, openingBrace)
|
2016-04-15 20:38:42 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2017-06-10 03:02:42 +02:00
|
|
|
public getSpanOfEnclosingComment(fileName: string, position: number, onlyMultiLine: boolean): string {
|
2017-06-09 02:08:07 +02:00
|
|
|
return this.forwardJSONCall(
|
2017-06-10 03:02:42 +02:00
|
|
|
`getSpanOfEnclosingComment('${fileName}', ${position})`,
|
|
|
|
() => this.languageService.getSpanOfEnclosingComment(fileName, position, onlyMultiLine)
|
2017-06-09 02:08:07 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2014-07-19 01:55:11 +02:00
|
|
|
/// GET SMART INDENT
|
|
|
|
public getIndentationAtPosition(fileName: string, position: number, options: string /*Services.EditorOptions*/): string {
|
|
|
|
return this.forwardJSONCall(
|
2015-12-24 09:21:03 +01:00
|
|
|
`getIndentationAtPosition('${fileName}', ${position})`,
|
2014-07-19 01:55:11 +02:00
|
|
|
() => {
|
2016-01-07 18:16:14 +01:00
|
|
|
const localOptions: EditorOptions = JSON.parse(options);
|
2014-08-16 00:06:23 +02:00
|
|
|
return this.languageService.getIndentationAtPosition(fileName, position, localOptions);
|
2014-07-19 01:55:11 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/// GET REFERENCES
|
2014-09-24 21:55:27 +02:00
|
|
|
|
2014-07-19 01:55:11 +02:00
|
|
|
public getReferencesAtPosition(fileName: string, position: number): string {
|
|
|
|
return this.forwardJSONCall(
|
2015-12-24 09:21:03 +01:00
|
|
|
`getReferencesAtPosition('${fileName}', ${position})`,
|
2016-01-07 18:24:32 +01:00
|
|
|
() => this.languageService.getReferencesAtPosition(fileName, position)
|
|
|
|
);
|
2014-07-19 01:55:11 +02:00
|
|
|
}
|
2014-07-13 01:04:16 +02:00
|
|
|
|
2015-03-20 22:31:36 +01:00
|
|
|
public findReferences(fileName: string, position: number): string {
|
|
|
|
return this.forwardJSONCall(
|
2015-12-24 09:21:03 +01:00
|
|
|
`findReferences('${fileName}', ${position})`,
|
2016-01-07 18:24:32 +01:00
|
|
|
() => this.languageService.findReferences(fileName, position)
|
|
|
|
);
|
2015-03-20 22:31:36 +01:00
|
|
|
}
|
|
|
|
|
2020-12-11 21:37:02 +01:00
|
|
|
public getFileReferences(fileName: string) {
|
|
|
|
return this.forwardJSONCall(
|
|
|
|
`getFileReferences('${fileName})`,
|
|
|
|
() => this.languageService.getFileReferences(fileName)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2014-07-19 01:55:11 +02:00
|
|
|
public getOccurrencesAtPosition(fileName: string, position: number): string {
|
|
|
|
return this.forwardJSONCall(
|
2015-12-24 09:21:03 +01:00
|
|
|
`getOccurrencesAtPosition('${fileName}', ${position})`,
|
2016-01-07 18:24:32 +01:00
|
|
|
() => this.languageService.getOccurrencesAtPosition(fileName, position)
|
|
|
|
);
|
2014-07-19 01:55:11 +02:00
|
|
|
}
|
|
|
|
|
2015-04-09 08:16:16 +02:00
|
|
|
public getDocumentHighlights(fileName: string, position: number, filesToSearch: string): string {
|
2015-04-09 06:59:50 +02:00
|
|
|
return this.forwardJSONCall(
|
2015-12-24 09:21:03 +01:00
|
|
|
`getDocumentHighlights('${fileName}', ${position})`,
|
2015-04-09 06:59:50 +02:00
|
|
|
() => {
|
2016-01-07 18:16:14 +01:00
|
|
|
const results = this.languageService.getDocumentHighlights(fileName, position, JSON.parse(filesToSearch));
|
2016-02-25 21:08:44 +01:00
|
|
|
// workaround for VS document highlighting issue - keep only items from the initial file
|
2020-01-31 19:40:57 +01:00
|
|
|
const normalizedName = toFileNameLowerCase(normalizeSlashes(fileName));
|
|
|
|
return filter(results, r => toFileNameLowerCase(normalizeSlashes(r.fileName)) === normalizedName);
|
2015-04-09 06:59:50 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2014-07-19 01:55:11 +02:00
|
|
|
/// COMPLETION LISTS
|
2014-09-24 21:55:27 +02:00
|
|
|
|
|
|
|
/**
|
2015-05-05 22:36:59 +02:00
|
|
|
* Get a string based representation of the completions
|
|
|
|
* to provide at the given source position and providing a member completion
|
2014-09-24 21:55:27 +02:00
|
|
|
* list if requested.
|
|
|
|
*/
|
2021-11-16 01:39:52 +01:00
|
|
|
public getCompletionsAtPosition(fileName: string, position: number, preferences: GetCompletionsAtPositionOptions | undefined, formattingSettings: FormatCodeSettings | undefined) {
|
2014-07-19 01:55:11 +02:00
|
|
|
return this.forwardJSONCall(
|
2021-11-16 01:39:52 +01:00
|
|
|
`getCompletionsAtPosition('${fileName}', ${position}, ${preferences}, ${formattingSettings})`,
|
|
|
|
() => this.languageService.getCompletionsAtPosition(fileName, position, preferences, formattingSettings)
|
2016-01-07 18:24:32 +01:00
|
|
|
);
|
2014-07-19 01:55:11 +02:00
|
|
|
}
|
|
|
|
|
2014-09-24 21:55:27 +02:00
|
|
|
/** Get a string based representation of a completion list entry details */
|
2021-03-01 21:09:45 +01:00
|
|
|
public getCompletionEntryDetails(fileName: string, position: number, entryName: string, formatOptions: string/*Services.FormatCodeOptions*/ | undefined, source: string | undefined, preferences: UserPreferences | undefined, data: CompletionEntryData | undefined) {
|
2014-07-19 01:55:11 +02:00
|
|
|
return this.forwardJSONCall(
|
2016-01-07 18:00:20 +01:00
|
|
|
`getCompletionEntryDetails('${fileName}', ${position}, '${entryName}')`,
|
Add exported members of all project files in the global completion list (#19069)
* checker.ts: Remove null check on symbols
* tsserverProjectSystem.ts: add two tests
* client.ts, completions.ts, types.ts: Add codeActions member to CompletionEntryDetails
* protocol.ts, session.ts: Add codeActions member to CompletionEntryDetails protocol
* protocol.ts, session.ts, types.ts: add hasAction to CompletionEntry
* session.ts, services.ts, types.ts: Add formattingOptions parameter to getCompletionEntryDetails
* completions.ts: define SymbolOriginInfo type
* completions.ts, services.ts: Add allSourceFiles parameter to getCompletionsAtPosition
* completions.ts, services.ts: Plumb allSourceFiles into new function getSymbolsFromOtherSourceFileExports inside getCompletionData
* completions.ts: add symbolToOriginInfoMap parameter to getCompletionEntriesFromSymbols and to return value of getCompletionData
* utilities.ts: Add getOtherModuleSymbols, getUniqueSymbolIdAsString, getUniqueSymbolId
* completions.ts: Set CompletionEntry.hasAction when symbol is found in symbolToOriginInfoMap (meaning there's an import action)
* completions.ts: Populate list with possible exports (implement getSymbolsFromOtherSourceFileExports)
* completions.ts, services.ts: Plumb host and rulesProvider into getCompletionEntryDetails
* completions.ts: Add TODO comment
* importFixes.ts: Add types ImportDeclarationMap and ImportCodeFixContext
* Move getImportDeclarations into getCodeActionForImport, immediately after the implementation
* importFixes.ts: Move createChangeTracker into getCodeActionForImport, immediately after getImportDeclarations
* importFixes.ts: Add convertToImportCodeFixContext function and reference it from the getCodeActions lambda
* importFixes.ts: Add context: ImportCodeFixContext parameter to getCodeActionForImport, update call sites, destructure it, use compilerOptions in getModuleSpecifierForNewImport
* importFixes.ts: Remove moduleSymbol parameter from getImportDeclarations and use the ambient one
* importFixes.ts: Use cachedImportDeclarations from context in getCodeActionForImport
* importFixes.ts: Move createCodeAction out, immediately above convertToImportCodeFixContext
* Move the declaration for lastImportDeclaration out of the getCodeActions lambda into getCodeActionForImport
* importFixes.ts: Use symbolToken in getCodeActionForImport
* importFixes.ts: Remove useCaseSensitiveFileNames altogether from getCodeActions lambda
* importFixes.ts: Remove local getUniqueSymbolId function and add checker parameter to calls to it
* importFixes.ts: Move getCodeActionForImport out into an export, immediately below convertToImportCodeFixContext
* completions.ts: In getCompletionEntryDetails, if there's symbolOriginInfo, call getCodeActionForImport
* importFixes.ts: Create and use importFixContext within getCodeActions lambda
* importFixes.ts: Use local newLineCharacter instead of context.newLineCharacter in getCodeActionForImport
* importFixes.ts: Use local host instead of context.host in getCodeActionForImport
* importFixes.ts: Remove dummy getCanonicalFileName line
* Filter symbols after gathering exports instead of before
* Lint
* Test, fix bugs, refactor
* Suggestions from code review
* Update api baseline
* Fix bug if previousToken is not an Identifier
* Replace `startsWith` with `stringContainsCharactersInOrder`
2017-10-17 19:20:11 +02:00
|
|
|
() => {
|
2018-03-20 21:07:59 +01:00
|
|
|
const localOptions: FormatCodeOptions = formatOptions === undefined ? undefined : JSON.parse(formatOptions);
|
2021-03-01 21:09:45 +01:00
|
|
|
return this.languageService.getCompletionEntryDetails(fileName, position, entryName, localOptions, source, preferences, data);
|
Add exported members of all project files in the global completion list (#19069)
* checker.ts: Remove null check on symbols
* tsserverProjectSystem.ts: add two tests
* client.ts, completions.ts, types.ts: Add codeActions member to CompletionEntryDetails
* protocol.ts, session.ts: Add codeActions member to CompletionEntryDetails protocol
* protocol.ts, session.ts, types.ts: add hasAction to CompletionEntry
* session.ts, services.ts, types.ts: Add formattingOptions parameter to getCompletionEntryDetails
* completions.ts: define SymbolOriginInfo type
* completions.ts, services.ts: Add allSourceFiles parameter to getCompletionsAtPosition
* completions.ts, services.ts: Plumb allSourceFiles into new function getSymbolsFromOtherSourceFileExports inside getCompletionData
* completions.ts: add symbolToOriginInfoMap parameter to getCompletionEntriesFromSymbols and to return value of getCompletionData
* utilities.ts: Add getOtherModuleSymbols, getUniqueSymbolIdAsString, getUniqueSymbolId
* completions.ts: Set CompletionEntry.hasAction when symbol is found in symbolToOriginInfoMap (meaning there's an import action)
* completions.ts: Populate list with possible exports (implement getSymbolsFromOtherSourceFileExports)
* completions.ts, services.ts: Plumb host and rulesProvider into getCompletionEntryDetails
* completions.ts: Add TODO comment
* importFixes.ts: Add types ImportDeclarationMap and ImportCodeFixContext
* Move getImportDeclarations into getCodeActionForImport, immediately after the implementation
* importFixes.ts: Move createChangeTracker into getCodeActionForImport, immediately after getImportDeclarations
* importFixes.ts: Add convertToImportCodeFixContext function and reference it from the getCodeActions lambda
* importFixes.ts: Add context: ImportCodeFixContext parameter to getCodeActionForImport, update call sites, destructure it, use compilerOptions in getModuleSpecifierForNewImport
* importFixes.ts: Remove moduleSymbol parameter from getImportDeclarations and use the ambient one
* importFixes.ts: Use cachedImportDeclarations from context in getCodeActionForImport
* importFixes.ts: Move createCodeAction out, immediately above convertToImportCodeFixContext
* Move the declaration for lastImportDeclaration out of the getCodeActions lambda into getCodeActionForImport
* importFixes.ts: Use symbolToken in getCodeActionForImport
* importFixes.ts: Remove useCaseSensitiveFileNames altogether from getCodeActions lambda
* importFixes.ts: Remove local getUniqueSymbolId function and add checker parameter to calls to it
* importFixes.ts: Move getCodeActionForImport out into an export, immediately below convertToImportCodeFixContext
* completions.ts: In getCompletionEntryDetails, if there's symbolOriginInfo, call getCodeActionForImport
* importFixes.ts: Create and use importFixContext within getCodeActions lambda
* importFixes.ts: Use local newLineCharacter instead of context.newLineCharacter in getCodeActionForImport
* importFixes.ts: Use local host instead of context.host in getCodeActionForImport
* importFixes.ts: Remove dummy getCanonicalFileName line
* Filter symbols after gathering exports instead of before
* Lint
* Test, fix bugs, refactor
* Suggestions from code review
* Update api baseline
* Fix bug if previousToken is not an Identifier
* Replace `startsWith` with `stringContainsCharactersInOrder`
2017-10-17 19:20:11 +02:00
|
|
|
}
|
2016-01-07 18:24:32 +01:00
|
|
|
);
|
2014-07-19 01:55:11 +02:00
|
|
|
}
|
|
|
|
|
2014-08-15 01:51:16 +02:00
|
|
|
public getFormattingEditsForRange(fileName: string, start: number, end: number, options: string/*Services.FormatCodeOptions*/): string {
|
2014-07-19 01:55:11 +02:00
|
|
|
return this.forwardJSONCall(
|
2015-12-24 09:21:03 +01:00
|
|
|
`getFormattingEditsForRange('${fileName}', ${start}, ${end})`,
|
2014-07-19 01:55:11 +02:00
|
|
|
() => {
|
2018-03-01 23:20:18 +01:00
|
|
|
const localOptions: FormatCodeOptions = JSON.parse(options);
|
2016-01-07 18:16:14 +01:00
|
|
|
return this.languageService.getFormattingEditsForRange(fileName, start, end, localOptions);
|
2014-07-19 01:55:11 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2014-08-15 01:51:16 +02:00
|
|
|
public getFormattingEditsForDocument(fileName: string, options: string/*Services.FormatCodeOptions*/): string {
|
2014-07-19 01:55:11 +02:00
|
|
|
return this.forwardJSONCall(
|
2015-12-24 09:21:03 +01:00
|
|
|
`getFormattingEditsForDocument('${fileName}')`,
|
2014-07-19 01:55:11 +02:00
|
|
|
() => {
|
2018-03-01 23:20:18 +01:00
|
|
|
const localOptions: FormatCodeOptions = JSON.parse(options);
|
2016-01-07 18:16:14 +01:00
|
|
|
return this.languageService.getFormattingEditsForDocument(fileName, localOptions);
|
2014-07-19 01:55:11 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
public getFormattingEditsAfterKeystroke(fileName: string, position: number, key: string, options: string/*Services.FormatCodeOptions*/): string {
|
|
|
|
return this.forwardJSONCall(
|
2015-12-24 09:21:03 +01:00
|
|
|
`getFormattingEditsAfterKeystroke('${fileName}', ${position}, '${key}')`,
|
2014-07-19 01:55:11 +02:00
|
|
|
() => {
|
2018-03-01 23:20:18 +01:00
|
|
|
const localOptions: FormatCodeOptions = JSON.parse(options);
|
2016-01-07 18:16:14 +01:00
|
|
|
return this.languageService.getFormattingEditsAfterKeystroke(fileName, position, key, localOptions);
|
2014-07-19 01:55:11 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-02-06 00:24:48 +01:00
|
|
|
public getDocCommentTemplateAtPosition(fileName: string, position: number, options?: DocCommentTemplateOptions): string {
|
2015-07-14 03:56:38 +02:00
|
|
|
return this.forwardJSONCall(
|
2015-12-24 09:21:03 +01:00
|
|
|
`getDocCommentTemplateAtPosition('${fileName}', ${position})`,
|
2021-02-06 00:24:48 +01:00
|
|
|
() => this.languageService.getDocCommentTemplateAtPosition(fileName, position, options)
|
2015-07-21 03:31:17 +02:00
|
|
|
);
|
2015-07-14 03:56:38 +02:00
|
|
|
}
|
|
|
|
|
2014-07-19 01:55:11 +02:00
|
|
|
/// NAVIGATE TO
|
2014-09-24 21:55:27 +02:00
|
|
|
|
|
|
|
/** Return a list of symbols that are interesting to navigate to */
|
2016-09-13 02:17:52 +02:00
|
|
|
public getNavigateToItems(searchValue: string, maxResultCount?: number, fileName?: string): string {
|
2014-07-19 01:55:11 +02:00
|
|
|
return this.forwardJSONCall(
|
2016-09-13 02:17:52 +02:00
|
|
|
`getNavigateToItems('${searchValue}', ${maxResultCount}, ${fileName})`,
|
|
|
|
() => this.languageService.getNavigateToItems(searchValue, maxResultCount, fileName)
|
2016-01-07 18:24:32 +01:00
|
|
|
);
|
2014-07-19 01:55:11 +02:00
|
|
|
}
|
|
|
|
|
2014-08-15 01:51:16 +02:00
|
|
|
public getNavigationBarItems(fileName: string): string {
|
2014-07-19 01:55:11 +02:00
|
|
|
return this.forwardJSONCall(
|
2015-12-24 09:21:03 +01:00
|
|
|
`getNavigationBarItems('${fileName}')`,
|
2016-01-07 18:24:32 +01:00
|
|
|
() => this.languageService.getNavigationBarItems(fileName)
|
|
|
|
);
|
2014-07-19 01:55:11 +02:00
|
|
|
}
|
|
|
|
|
2016-10-11 16:48:28 +02:00
|
|
|
public getNavigationTree(fileName: string): string {
|
|
|
|
return this.forwardJSONCall(
|
|
|
|
`getNavigationTree('${fileName}')`,
|
|
|
|
() => this.languageService.getNavigationTree(fileName)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2014-08-15 01:51:16 +02:00
|
|
|
public getOutliningSpans(fileName: string): string {
|
2014-07-19 01:55:11 +02:00
|
|
|
return this.forwardJSONCall(
|
2015-12-24 09:21:03 +01:00
|
|
|
`getOutliningSpans('${fileName}')`,
|
2016-01-07 18:24:32 +01:00
|
|
|
() => this.languageService.getOutliningSpans(fileName)
|
|
|
|
);
|
2014-08-15 01:51:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public getTodoComments(fileName: string, descriptors: string): string {
|
|
|
|
return this.forwardJSONCall(
|
2015-12-24 09:21:03 +01:00
|
|
|
`getTodoComments('${fileName}')`,
|
2016-01-07 18:24:32 +01:00
|
|
|
() => this.languageService.getTodoComments(fileName, JSON.parse(descriptors))
|
|
|
|
);
|
2014-07-19 01:55:11 +02:00
|
|
|
}
|
|
|
|
|
2019-12-22 22:25:09 +01:00
|
|
|
/// CALL HIERARCHY
|
|
|
|
|
|
|
|
public prepareCallHierarchy(fileName: string, position: number): string {
|
|
|
|
return this.forwardJSONCall(
|
|
|
|
`prepareCallHierarchy('${fileName}', ${position})`,
|
|
|
|
() => this.languageService.prepareCallHierarchy(fileName, position)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public provideCallHierarchyIncomingCalls(fileName: string, position: number): string {
|
|
|
|
return this.forwardJSONCall(
|
|
|
|
`provideCallHierarchyIncomingCalls('${fileName}', ${position})`,
|
|
|
|
() => this.languageService.provideCallHierarchyIncomingCalls(fileName, position)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public provideCallHierarchyOutgoingCalls(fileName: string, position: number): string {
|
|
|
|
return this.forwardJSONCall(
|
|
|
|
`provideCallHierarchyOutgoingCalls('${fileName}', ${position})`,
|
|
|
|
() => this.languageService.provideCallHierarchyOutgoingCalls(fileName, position)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-06-25 08:06:34 +02:00
|
|
|
public provideInlayHints(fileName: string, span: TextSpan, preference: InlayHintsOptions | undefined): string {
|
|
|
|
return this.forwardJSONCall(
|
|
|
|
`provideInlayHints('${fileName}', '${JSON.stringify(span)}', ${JSON.stringify(preference)})`,
|
|
|
|
() => this.languageService.provideInlayHints(fileName, span, preference)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2014-07-19 01:55:11 +02:00
|
|
|
/// Emit
|
|
|
|
public getEmitOutput(fileName: string): string {
|
|
|
|
return this.forwardJSONCall(
|
2015-12-24 09:21:03 +01:00
|
|
|
`getEmitOutput('${fileName}')`,
|
2020-03-19 22:03:21 +01:00
|
|
|
() => {
|
|
|
|
const { diagnostics, ...rest } = this.languageService.getEmitOutput(fileName);
|
|
|
|
return { ...rest, diagnostics: this.realizeDiagnostics(diagnostics) };
|
|
|
|
}
|
2016-01-07 18:24:32 +01:00
|
|
|
);
|
2014-07-19 01:55:11 +02:00
|
|
|
}
|
2016-07-02 02:35:12 +02:00
|
|
|
|
2017-10-10 19:54:29 +02:00
|
|
|
public getEmitOutputObject(fileName: string): EmitOutput {
|
2016-07-02 02:35:12 +02:00
|
|
|
return forwardCall(
|
2016-07-02 05:30:08 +02:00
|
|
|
this.logger,
|
2016-07-02 02:35:12 +02:00
|
|
|
`getEmitOutput('${fileName}')`,
|
|
|
|
/*returnJson*/ false,
|
|
|
|
() => this.languageService.getEmitOutput(fileName),
|
2017-10-10 19:54:29 +02:00
|
|
|
this.logPerformance) as EmitOutput;
|
2016-07-02 02:35:12 +02:00
|
|
|
}
|
2020-02-21 02:00:23 +01:00
|
|
|
|
2020-03-03 01:30:42 +01:00
|
|
|
public toggleLineComment(fileName: string, textRange: TextRange): string {
|
2020-02-21 02:00:23 +01:00
|
|
|
return this.forwardJSONCall(
|
2020-02-27 21:57:51 +01:00
|
|
|
`toggleLineComment('${fileName}', '${JSON.stringify(textRange)}')`,
|
|
|
|
() => this.languageService.toggleLineComment(fileName, textRange)
|
2020-02-21 02:00:23 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-03-03 01:30:42 +01:00
|
|
|
public toggleMultilineComment(fileName: string, textRange: TextRange): string {
|
2020-02-21 02:00:23 +01:00
|
|
|
return this.forwardJSONCall(
|
2020-02-27 21:57:51 +01:00
|
|
|
`toggleMultilineComment('${fileName}', '${JSON.stringify(textRange)}')`,
|
|
|
|
() => this.languageService.toggleMultilineComment(fileName, textRange)
|
2020-02-21 02:00:23 +01:00
|
|
|
);
|
|
|
|
}
|
2020-02-29 03:45:56 +01:00
|
|
|
|
2020-03-03 01:30:42 +01:00
|
|
|
public commentSelection(fileName: string, textRange: TextRange): string {
|
2020-02-29 03:45:56 +01:00
|
|
|
return this.forwardJSONCall(
|
|
|
|
`commentSelection('${fileName}', '${JSON.stringify(textRange)}')`,
|
|
|
|
() => this.languageService.commentSelection(fileName, textRange)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-03-03 01:30:42 +01:00
|
|
|
public uncommentSelection(fileName: string, textRange: TextRange): string {
|
2020-02-29 03:45:56 +01:00
|
|
|
return this.forwardJSONCall(
|
|
|
|
`uncommentSelection('${fileName}', '${JSON.stringify(textRange)}')`,
|
|
|
|
() => this.languageService.uncommentSelection(fileName, textRange)
|
|
|
|
);
|
|
|
|
}
|
2014-07-19 01:55:11 +02:00
|
|
|
}
|
|
|
|
|
2015-04-30 23:26:46 +02:00
|
|
|
function convertClassifications(classifications: Classifications): { spans: string, endOfLineState: EndOfLineState } {
|
|
|
|
return { spans: classifications.spans.join(","), endOfLineState: classifications.endOfLineState };
|
|
|
|
}
|
|
|
|
|
2014-07-24 21:00:45 +02:00
|
|
|
class ClassifierShimObject extends ShimBase implements ClassifierShim {
|
2014-07-24 20:57:18 +02:00
|
|
|
public classifier: Classifier;
|
2015-06-12 22:49:38 +02:00
|
|
|
private logPerformance = false;
|
2014-07-19 01:55:11 +02:00
|
|
|
|
2015-05-01 01:14:43 +02:00
|
|
|
constructor(factory: ShimFactory, private logger: Logger) {
|
2014-07-19 01:55:11 +02:00
|
|
|
super(factory);
|
2015-01-15 02:05:50 +01:00
|
|
|
this.classifier = createClassifier();
|
2014-07-19 01:55:11 +02:00
|
|
|
}
|
|
|
|
|
2018-05-22 23:46:57 +02:00
|
|
|
public getEncodedLexicalClassifications(text: string, lexState: EndOfLineState, syntacticClassifierAbsent = false): string {
|
2015-05-01 02:39:51 +02:00
|
|
|
return forwardJSONCall(this.logger, "getEncodedLexicalClassifications",
|
|
|
|
() => convertClassifications(this.classifier.getEncodedLexicalClassifications(text, lexState, syntacticClassifierAbsent)),
|
2015-06-12 22:49:38 +02:00
|
|
|
this.logPerformance);
|
2015-04-30 23:26:46 +02:00
|
|
|
}
|
|
|
|
|
2014-07-19 01:55:11 +02:00
|
|
|
/// COLORIZATION
|
2018-05-22 23:46:57 +02:00
|
|
|
public getClassificationsForLine(text: string, lexState: EndOfLineState, classifyKeywordsInGenerics = false): string {
|
2016-01-07 18:16:14 +01:00
|
|
|
const classification = this.classifier.getClassificationsForLine(text, lexState, classifyKeywordsInGenerics);
|
2015-12-24 09:21:03 +01:00
|
|
|
let result = "";
|
2016-01-07 18:16:14 +01:00
|
|
|
for (const item of classification.entries) {
|
2015-12-24 09:21:03 +01:00
|
|
|
result += item.length + "\n";
|
|
|
|
result += item.classification + "\n";
|
2014-07-19 01:55:11 +02:00
|
|
|
}
|
|
|
|
result += classification.finalLexState;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-24 21:00:45 +02:00
|
|
|
class CoreServicesShimObject extends ShimBase implements CoreServicesShim {
|
2015-06-12 22:49:38 +02:00
|
|
|
private logPerformance = false;
|
2017-07-27 19:54:47 +02:00
|
|
|
private safeList: JsTyping.SafeList | undefined;
|
2015-04-21 22:24:02 +02:00
|
|
|
|
2017-07-14 23:26:13 +02:00
|
|
|
constructor(factory: ShimFactory, public readonly logger: Logger, private readonly host: CoreServicesShimHostAdapter) {
|
2014-07-19 01:55:11 +02:00
|
|
|
super(factory);
|
|
|
|
}
|
|
|
|
|
2017-10-10 19:54:29 +02:00
|
|
|
private forwardJSONCall(actionDescription: string, action: () => {}): string {
|
2015-06-12 22:49:38 +02:00
|
|
|
return forwardJSONCall(this.logger, actionDescription, action, this.logPerformance);
|
2014-07-19 01:55:11 +02:00
|
|
|
}
|
2015-12-24 09:21:03 +01:00
|
|
|
|
2015-07-14 02:44:50 +02:00
|
|
|
public resolveModuleName(fileName: string, moduleName: string, compilerOptionsJson: string): string {
|
|
|
|
return this.forwardJSONCall(`resolveModuleName('${fileName}')`, () => {
|
2021-05-18 15:20:57 +02:00
|
|
|
const compilerOptions = JSON.parse(compilerOptionsJson) as CompilerOptions;
|
2015-09-10 20:36:31 +02:00
|
|
|
const result = resolveModuleName(moduleName, normalizeSlashes(fileName), compilerOptions, this.host);
|
2017-05-10 20:38:10 +02:00
|
|
|
let resolvedFileName = result.resolvedModule ? result.resolvedModule.resolvedFileName : undefined;
|
|
|
|
if (result.resolvedModule && result.resolvedModule.extension !== Extension.Ts && result.resolvedModule.extension !== Extension.Tsx && result.resolvedModule.extension !== Extension.Dts) {
|
|
|
|
resolvedFileName = undefined;
|
|
|
|
}
|
|
|
|
|
2015-09-10 20:36:31 +02:00
|
|
|
return {
|
2016-11-14 21:46:56 +01:00
|
|
|
resolvedFileName,
|
2015-09-10 20:36:31 +02:00
|
|
|
failedLookupLocations: result.failedLookupLocations
|
|
|
|
};
|
2015-12-24 09:21:03 +01:00
|
|
|
});
|
2015-07-14 02:44:50 +02:00
|
|
|
}
|
2014-07-19 01:55:11 +02:00
|
|
|
|
2016-04-06 01:33:11 +02:00
|
|
|
public resolveTypeReferenceDirective(fileName: string, typeReferenceDirective: string, compilerOptionsJson: string): string {
|
2016-04-01 21:41:01 +02:00
|
|
|
return this.forwardJSONCall(`resolveTypeReferenceDirective(${fileName})`, () => {
|
2021-05-18 15:20:57 +02:00
|
|
|
const compilerOptions = JSON.parse(compilerOptionsJson) as CompilerOptions;
|
2016-04-06 01:33:11 +02:00
|
|
|
const result = resolveTypeReferenceDirective(typeReferenceDirective, normalizeSlashes(fileName), compilerOptions, this.host);
|
2016-04-01 21:41:01 +02:00
|
|
|
return {
|
|
|
|
resolvedFileName: result.resolvedTypeReferenceDirective ? result.resolvedTypeReferenceDirective.resolvedFileName : undefined,
|
|
|
|
primary: result.resolvedTypeReferenceDirective ? result.resolvedTypeReferenceDirective.primary : true,
|
|
|
|
failedLookupLocations: result.failedLookupLocations
|
|
|
|
};
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2014-11-18 02:01:23 +01:00
|
|
|
public getPreProcessedFileInfo(fileName: string, sourceTextSnapshot: IScriptSnapshot): string {
|
2014-07-19 01:55:11 +02:00
|
|
|
return this.forwardJSONCall(
|
2016-08-04 16:43:54 +02:00
|
|
|
`getPreProcessedFileInfo('${fileName}')`,
|
2014-07-19 01:55:11 +02:00
|
|
|
() => {
|
2016-06-03 18:33:17 +02:00
|
|
|
// for now treat files as JavaScript
|
2018-01-12 19:44:39 +01:00
|
|
|
const result = preProcessFile(getSnapshotText(sourceTextSnapshot), /* readImportFiles */ true, /* detectJavaScriptImports */ true);
|
2016-04-01 21:41:01 +02:00
|
|
|
return {
|
|
|
|
referencedFiles: this.convertFileReferences(result.referencedFiles),
|
|
|
|
importedFiles: this.convertFileReferences(result.importedFiles),
|
2015-07-30 01:25:22 +02:00
|
|
|
ambientExternalModules: result.ambientExternalModules,
|
2016-04-01 21:41:01 +02:00
|
|
|
isLibFile: result.isLibFile,
|
2018-05-03 20:00:10 +02:00
|
|
|
typeReferenceDirectives: this.convertFileReferences(result.typeReferenceDirectives),
|
|
|
|
libReferenceDirectives: this.convertFileReferences(result.libReferenceDirectives)
|
2014-10-28 22:45:32 +01:00
|
|
|
};
|
2016-04-01 21:41:01 +02:00
|
|
|
});
|
|
|
|
}
|
2014-10-28 22:45:32 +01:00
|
|
|
|
2016-08-04 16:43:54 +02:00
|
|
|
public getAutomaticTypeDirectiveNames(compilerOptionsJson: string): string {
|
|
|
|
return this.forwardJSONCall(
|
|
|
|
`getAutomaticTypeDirectiveNames('${compilerOptionsJson}')`,
|
|
|
|
() => {
|
2021-05-18 15:20:57 +02:00
|
|
|
const compilerOptions = JSON.parse(compilerOptionsJson) as CompilerOptions;
|
2016-08-04 16:43:54 +02:00
|
|
|
return getAutomaticTypeDirectiveNames(compilerOptions, this.host);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2018-05-22 23:46:57 +02:00
|
|
|
private convertFileReferences(refs: FileReference[]): ShimsFileReference[] | undefined {
|
2016-04-01 21:41:01 +02:00
|
|
|
if (!refs) {
|
|
|
|
return undefined;
|
|
|
|
}
|
2017-11-03 01:20:18 +01:00
|
|
|
const result: ShimsFileReference[] = [];
|
2016-04-01 21:41:01 +02:00
|
|
|
for (const ref of refs) {
|
|
|
|
result.push({
|
|
|
|
path: normalizeSlashes(ref.fileName),
|
|
|
|
position: ref.pos,
|
|
|
|
length: ref.end - ref.pos
|
2014-07-19 01:55:11 +02:00
|
|
|
});
|
2016-04-01 21:41:01 +02:00
|
|
|
}
|
|
|
|
return result;
|
2014-07-19 01:55:11 +02:00
|
|
|
}
|
|
|
|
|
2015-04-21 22:24:02 +02:00
|
|
|
public getTSConfigFileInfo(fileName: string, sourceTextSnapshot: IScriptSnapshot): string {
|
|
|
|
return this.forwardJSONCall(
|
2015-12-24 09:21:03 +01:00
|
|
|
`getTSConfigFileInfo('${fileName}')`,
|
2015-04-21 22:24:02 +02:00
|
|
|
() => {
|
2018-01-12 19:44:39 +01:00
|
|
|
const result = parseJsonText(fileName, getSnapshotText(sourceTextSnapshot));
|
2016-01-21 19:43:07 +01:00
|
|
|
const normalizedFileName = normalizeSlashes(fileName);
|
2016-11-24 01:09:34 +01:00
|
|
|
const configFile = parseJsonSourceFileConfigFileContent(result, this.host, getDirectoryPath(normalizedFileName), /*existingOptions*/ {}, normalizedFileName);
|
2015-04-21 22:24:02 +02:00
|
|
|
|
|
|
|
return {
|
|
|
|
options: configFile.options,
|
2016-11-19 02:46:06 +01:00
|
|
|
typeAcquisition: configFile.typeAcquisition,
|
2015-04-21 22:24:02 +02:00
|
|
|
files: configFile.fileNames,
|
2016-05-06 19:12:12 +02:00
|
|
|
raw: configFile.raw,
|
2018-05-22 20:01:18 +02:00
|
|
|
errors: realizeDiagnostics([...result.parseDiagnostics, ...configFile.errors], "\r\n")
|
2015-04-21 22:24:02 +02:00
|
|
|
};
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2014-07-19 01:55:11 +02:00
|
|
|
public getDefaultCompilationSettings(): string {
|
|
|
|
return this.forwardJSONCall(
|
|
|
|
"getDefaultCompilationSettings()",
|
2016-01-07 18:24:32 +01:00
|
|
|
() => getDefaultCompilerOptions()
|
|
|
|
);
|
2014-07-19 01:55:11 +02:00
|
|
|
}
|
2016-02-22 06:35:02 +01:00
|
|
|
|
2016-03-02 03:52:11 +01:00
|
|
|
public discoverTypings(discoverTypingsJson: string): string {
|
2016-02-22 06:35:02 +01:00
|
|
|
const getCanonicalFileName = createGetCanonicalFileName(/*useCaseSensitivefileNames:*/ false);
|
2016-02-25 21:32:43 +01:00
|
|
|
return this.forwardJSONCall("discoverTypings()", () => {
|
2021-05-18 15:20:57 +02:00
|
|
|
const info = JSON.parse(discoverTypingsJson) as DiscoverTypingsInfo;
|
2017-07-27 19:54:47 +02:00
|
|
|
if (this.safeList === undefined) {
|
|
|
|
this.safeList = JsTyping.loadSafeList(this.host, toPath(info.safeListPath, info.safeListPath, getCanonicalFileName));
|
|
|
|
}
|
|
|
|
return JsTyping.discoverTypings(
|
2016-02-22 06:35:02 +01:00
|
|
|
this.host,
|
2017-07-13 16:10:35 +02:00
|
|
|
msg => this.logger.log(msg),
|
2016-03-02 19:11:13 +01:00
|
|
|
info.fileNames,
|
|
|
|
toPath(info.projectRootPath, info.projectRootPath, getCanonicalFileName),
|
2017-07-27 19:54:47 +02:00
|
|
|
this.safeList,
|
2016-10-28 00:50:21 +02:00
|
|
|
info.packageNameToTypingLocation,
|
2016-11-19 02:46:06 +01:00
|
|
|
info.typeAcquisition,
|
2018-01-11 20:11:26 +01:00
|
|
|
info.unresolvedImports,
|
|
|
|
info.typesRegistry);
|
2016-02-22 06:35:02 +01:00
|
|
|
});
|
|
|
|
}
|
2014-07-13 01:04:16 +02:00
|
|
|
}
|
2014-07-24 20:42:55 +02:00
|
|
|
|
2014-07-24 21:00:45 +02:00
|
|
|
export class TypeScriptServicesFactory implements ShimFactory {
|
|
|
|
private _shims: Shim[] = [];
|
2018-11-17 01:02:23 +01:00
|
|
|
private documentRegistry: DocumentRegistry | undefined;
|
2014-07-24 20:42:55 +02:00
|
|
|
|
2014-12-07 08:04:17 +01:00
|
|
|
/*
|
|
|
|
* Returns script API version.
|
|
|
|
*/
|
2014-12-08 06:41:15 +01:00
|
|
|
public getServicesVersion(): string {
|
|
|
|
return servicesVersion;
|
2014-12-07 08:04:17 +01:00
|
|
|
}
|
|
|
|
|
2014-07-24 21:00:45 +02:00
|
|
|
public createLanguageServiceShim(host: LanguageServiceShimHost): LanguageServiceShim {
|
2014-07-24 20:42:55 +02:00
|
|
|
try {
|
2015-06-03 22:48:34 +02:00
|
|
|
if (this.documentRegistry === undefined) {
|
2015-11-06 23:16:44 +01:00
|
|
|
this.documentRegistry = createDocumentRegistry(host.useCaseSensitiveFileNames && host.useCaseSensitiveFileNames(), host.getCurrentDirectory());
|
2015-06-03 22:48:34 +02:00
|
|
|
}
|
2016-01-07 18:16:14 +01:00
|
|
|
const hostAdapter = new LanguageServiceShimHostAdapter(host);
|
2018-04-03 22:40:48 +02:00
|
|
|
const languageService = createLanguageService(hostAdapter, this.documentRegistry, /*syntaxOnly*/ false);
|
2014-08-08 08:32:43 +02:00
|
|
|
return new LanguageServiceShimObject(this, host, languageService);
|
2014-07-24 20:42:55 +02:00
|
|
|
}
|
|
|
|
catch (err) {
|
2014-07-24 20:57:18 +02:00
|
|
|
logInternalError(host, err);
|
2014-07-24 20:42:55 +02:00
|
|
|
throw err;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-17 04:03:07 +02:00
|
|
|
public createClassifierShim(logger: Logger): ClassifierShim {
|
2014-07-24 20:42:55 +02:00
|
|
|
try {
|
2015-05-01 01:14:43 +02:00
|
|
|
return new ClassifierShimObject(this, logger);
|
2014-07-24 20:42:55 +02:00
|
|
|
}
|
|
|
|
catch (err) {
|
2014-08-17 04:03:07 +02:00
|
|
|
logInternalError(logger, err);
|
2014-07-24 20:42:55 +02:00
|
|
|
throw err;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-21 22:24:02 +02:00
|
|
|
public createCoreServicesShim(host: CoreServicesShimHost): CoreServicesShim {
|
2014-07-24 20:42:55 +02:00
|
|
|
try {
|
2016-01-07 18:16:14 +01:00
|
|
|
const adapter = new CoreServicesShimHostAdapter(host);
|
2021-05-18 15:20:57 +02:00
|
|
|
return new CoreServicesShimObject(this, host as Logger, adapter);
|
2014-07-24 20:42:55 +02:00
|
|
|
}
|
|
|
|
catch (err) {
|
2021-05-18 15:20:57 +02:00
|
|
|
logInternalError(host as Logger, err);
|
2014-07-24 20:42:55 +02:00
|
|
|
throw err;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public close(): void {
|
|
|
|
// Forget all the registered shims
|
2017-07-18 20:08:44 +02:00
|
|
|
clear(this._shims);
|
2021-03-25 22:46:16 +01:00
|
|
|
this.documentRegistry = undefined;
|
2014-07-24 20:42:55 +02:00
|
|
|
}
|
|
|
|
|
2014-07-24 21:00:45 +02:00
|
|
|
public registerShim(shim: Shim): void {
|
2014-07-24 20:42:55 +02:00
|
|
|
this._shims.push(shim);
|
|
|
|
}
|
|
|
|
|
2014-07-24 21:00:45 +02:00
|
|
|
public unregisterShim(shim: Shim): void {
|
2016-12-19 19:12:35 +01:00
|
|
|
for (let i = 0; i < this._shims.length; i++) {
|
2014-07-24 20:42:55 +02:00
|
|
|
if (this._shims[i] === shim) {
|
|
|
|
delete this._shims[i];
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-18 02:01:23 +01:00
|
|
|
throw new Error("Invalid operation");
|
2014-07-24 20:42:55 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-03-17 23:26:55 +01:00
|
|
|
|
2020-01-31 19:40:57 +01:00
|
|
|
/* eslint-enable no-in-operator */
|