TypeScript/src/services/types.ts

1619 lines
65 KiB
TypeScript
Raw Normal View History

namespace ts {
export interface Node {
getSourceFile(): SourceFile;
getChildCount(sourceFile?: SourceFile): number;
getChildAt(index: number, sourceFile?: SourceFile): Node;
getChildren(sourceFile?: SourceFile): Node[];
/* @internal */
2019-08-19 12:38:58 +02:00
getChildren(sourceFile?: SourceFileLike): Node[]; // eslint-disable-line @typescript-eslint/unified-signatures
getStart(sourceFile?: SourceFile, includeJsDocComment?: boolean): number;
/* @internal */
2019-08-19 12:38:58 +02:00
getStart(sourceFile?: SourceFileLike, includeJsDocComment?: boolean): number; // eslint-disable-line @typescript-eslint/unified-signatures
getFullStart(): number;
getEnd(): number;
getWidth(sourceFile?: SourceFileLike): number;
getFullWidth(): number;
getLeadingTriviaWidth(sourceFile?: SourceFile): number;
getFullText(sourceFile?: SourceFile): string;
getText(sourceFile?: SourceFile): string;
Enable '--strictNullChecks' (#22088) * Enable '--strictNullChecks' * Fix API baselines * Make sys.getEnvironmentVariable non-nullable * make properties optional instead of using `| undefined` in thier type * reportDiagnostics should be required * Declare firstAccessor as non-nullable * Make `some` a type guard * Fix `getEnvironmentVariable` definition in tests * Pretend transformFlags are always defined * Fix one more use of sys.getEnvironmentVariable * `requiredResponse` accepts undefined, remove assertions * Mark optional properties as optional instead of using `| undefined` * Mark optional properties as optional instead of using ` | undefined` * Remove unnecessary null assertions * Put the bang on the declaration instead of every use * Make `createMapFromTemplate` require a parameter * Mark `EmitResult.emittedFiles` and `EmitResult.sourceMaps` as optional * Plumb through undefined in emitLsit and EmitExpressionList * `ElementAccessExpression.argumentExpression` can not be `undefined` * Add overloads for `writeTokenText` * Make `shouldWriteSeparatingLineTerminator` argument non-nullable * Make `synthesizedNodeStartsOnNewLine` argument required * `PropertyAssignment.initializer` cannot be undefined * Use one `!` at declaration site instead of on every use site * Capture host in a constant and avoid null assertions * Remove few more unused assertions * Update baselines * Use parameter defaults * Update baselines * Fix lint * Make Symbol#valueDeclaration and Symbol#declarations non-optional to reduce assertions * Make Node#symbol and Type#symbol non-optional to reduce assertions * Make `flags` non-nullable to reduce assertions * Convert some asserts to type guards * Make `isNonLocalAlias` a type guard * Add overload for `getSymbolOfNode` for `Declaration` * Some more `getSymbolOfNode` changes * Push undefined suppression into `typeToTypeNodeHelper` * `NodeBuilderContext.tracker` is never `undefined` * use `Debug.assertDefined` * Remove unnecessary tag * Mark `LiteralType.freshType` and `LiteralTupe.regularType` as required
2018-05-22 23:46:57 +02:00
getFirstToken(sourceFile?: SourceFile): Node | undefined;
/* @internal */
getFirstToken(sourceFile?: SourceFileLike): Node | undefined; // eslint-disable-line @typescript-eslint/unified-signatures
Enable '--strictNullChecks' (#22088) * Enable '--strictNullChecks' * Fix API baselines * Make sys.getEnvironmentVariable non-nullable * make properties optional instead of using `| undefined` in thier type * reportDiagnostics should be required * Declare firstAccessor as non-nullable * Make `some` a type guard * Fix `getEnvironmentVariable` definition in tests * Pretend transformFlags are always defined * Fix one more use of sys.getEnvironmentVariable * `requiredResponse` accepts undefined, remove assertions * Mark optional properties as optional instead of using `| undefined` * Mark optional properties as optional instead of using ` | undefined` * Remove unnecessary null assertions * Put the bang on the declaration instead of every use * Make `createMapFromTemplate` require a parameter * Mark `EmitResult.emittedFiles` and `EmitResult.sourceMaps` as optional * Plumb through undefined in emitLsit and EmitExpressionList * `ElementAccessExpression.argumentExpression` can not be `undefined` * Add overloads for `writeTokenText` * Make `shouldWriteSeparatingLineTerminator` argument non-nullable * Make `synthesizedNodeStartsOnNewLine` argument required * `PropertyAssignment.initializer` cannot be undefined * Use one `!` at declaration site instead of on every use site * Capture host in a constant and avoid null assertions * Remove few more unused assertions * Update baselines * Use parameter defaults * Update baselines * Fix lint * Make Symbol#valueDeclaration and Symbol#declarations non-optional to reduce assertions * Make Node#symbol and Type#symbol non-optional to reduce assertions * Make `flags` non-nullable to reduce assertions * Convert some asserts to type guards * Make `isNonLocalAlias` a type guard * Add overload for `getSymbolOfNode` for `Declaration` * Some more `getSymbolOfNode` changes * Push undefined suppression into `typeToTypeNodeHelper` * `NodeBuilderContext.tracker` is never `undefined` * use `Debug.assertDefined` * Remove unnecessary tag * Mark `LiteralType.freshType` and `LiteralTupe.regularType` as required
2018-05-22 23:46:57 +02:00
getLastToken(sourceFile?: SourceFile): Node | undefined;
/* @internal */
getLastToken(sourceFile?: SourceFileLike): Node | undefined; // eslint-disable-line @typescript-eslint/unified-signatures
// See ts.forEachChild for documentation.
forEachChild<T>(cbNode: (node: Node) => T | undefined, cbNodeArray?: (nodes: NodeArray<Node>) => T | undefined): T | undefined;
}
export interface Identifier {
readonly text: string;
}
Private named instance fields (#30829) * Fix display of private names in language server Signed-off-by: Joseph Watts <jwatts43@bloomberg.net> Signed-off-by: Max Heiber <max.heiber@gmail.com> * Parse private names Signed-off-by: Max Heiber <max.heiber@gmail.com> * update parser error recovery tests to use ¬ not # The intent of the tests seemed to be to regiment the behavior of the parser when a weird symbol is encountered. The `#` is now taken by private identifiers, so `¬` seems like a good new choice for keeping the diff small, since it also fits in 16 bits (wide emojis would be treated as multiple characters, since the scanner uses ++). Signed-off-by: Max Heiber <max.heiber@gmail.com> * Private Name Support in the Checker (#5) - [x] treat private names as unique: - case 1: cannot say that a variable is of a class type unless the variable points to an instance of the class - see [test](https://github.com/mheiber/TypeScript/tree/checker/tests/cases/conformance/classes/members/privateNames/privateNamesUnique.ts) - case 2: private names in class hierarchies do not conflict - see [test](https://github.com/mheiber/TypeScript/tree/checker/tests/cases/conformance/classes/members/privateNames/privateNamesNoConflictWhenInheriting.ts) - [x] `#constructor` is reserved - see [test](https://github.com/mheiber/TypeScript/tree/checker/tests/cases/conformance/classes/members/privateNames/privateNameConstructorReserved.ts) - check in `bindWorker`, where every node is visited - [x] Accessibility modifiers can't be used with private names - see [test](https://github.com/mheiber/TypeScript/tree/checker/tests/cases/conformance/classes/members/privateNames/privateNamesNoAccessibilityModifiers.ts) - implemented in `checkAccessibilityModifiers`, using `ModifierFlags.AccessibilityModifier` - [x] `delete #foo` not allowed - [x] Private name accesses not allowed outside of the defining class - see test: https://github.com/mheiber/TypeScript/tree/checker/tests/cases/conformance/classes/members/privateNames/privateNameNotAccessibleOutsideDefiningClass.ts - see [test](https://github.com/mheiber/TypeScript/tree/checker/tests/cases/conformance/classes/members/privateNames/privateNamesNoDelete.ts) - implemented in `checkDeleteExpression` - [x] Do [the right thing](https://gist.github.com/mheiber/b6fc7adb426c2e1cdaceb5d7786fc630) for nested classes mv private name tests together more checker tests for private names update naming and cleanup for check private names for private name support in the checker: - make names more consistent - remove unnecessary checks - add utility function to public API - other small cleanup Move getPropertyNameForUniqueESSymbol to utility for consistency with other calculation of special property names (starting with __), move the calculation of property names for unique es symbols to `utilities.ts`. private name tests strict+es6 Update private name tests to use 'strict' type checking and to target es6 instead of default. Makes the js output easier to read and tests more surface area with other checker features. error message for private names in obj literals Disallow decorating private-named properties because the spec is still in flux. Signed-off-by: Max Heiber <max.heiber@gmail.com> * Add private instance field transformation, pr feedback Implements private instance fields on top of the class properties refactor. This commit also includes incorporation of PR feedback on the checker, parser, and transformer in order to make the rebase manageable. Co-Authored-By: Max Heiber <max.heiber@gmail.com> Co-Authored-By: Ron Buckton <ron.buckton@microsoft.com> Signed-off-by: Joey Watts <jwatts43@bloomberg.net> Signed-off-by: Max Heiber <max.heiber@gmail.com> Incorporate PR feedback Fix checker crash with new block scoped bindings Add classExpressionInLoop test Update baselines for private name errors Apply suggestions from code review Fix privateNameFieldCallExpression test Remove unnecessary comment Fix PropertyAccessEntityNameExpression type Remove PrivateName from PropertyNameLiteral Add createPrivateName Remove PrivateName type from textSourceNode Add Debug asserts for invalid syntax kinds Don't output private name syntax when undeclared Make PrivateName extend Node Update baselines for public API Fix completions in language server Fix fourslash test crash intern private name descriptions undo expensive node.name.parent assignment Back the way things were on `master`: only assign node.name.parent when we need to Add tests for private names and JSDoc Patch hoverOverPrivateName fourslash test Fix goToDefinition for private-named fields remove Debug.fail for private name outside class Remove Debug.fail in binder.ts::`getDeclarationName`. It turns out this code path *does* get hit (intentionally). For best error messages, return `undefined` and rely on the parser generating a good error message "Private names are not allowed outside class bodies" Add rbuckton test cases for private names These test cases specifically exercise where we needed to use name-mangling. They are cases where private names have the same description. - private names no conflict when inheriting - private names distinct even when the two classes have the same name check dup instance+static private identifiers class A { #foo; static #foo; } not allowed because static and private names share the same lexical scope https://tc39.es/proposal-class-fields/#prod-ClassBody refactor getPropertyForPrivateName, rel spans refactor getPropertyForPrivateName so it is easier to read (use findAncestor instead of loop). Fix bugs in getPropertyForPrivateName: - make it work with deeply-nested classes with and without shadowing - make it catch shadowing when the conflict is between static and instance private name descriptions (these can actually clash) And add related spans to diagnostics for getPropertyForPrivateName catch conflicts between static and instance private identifiers: - cannot have an instance and static private identifier with the same spelling, as there is only one namespace for private names rename 'PrivateName' to 'PrivateIdentifier' to match the change of wording in the spec prposal: https://tc39.es/proposal-class-fields/#sec-syntax The rename in the spec was to avoid confusion between the AST Node PrivateIdentifier and the internal spec type PrivateName. So one uses the [[Description]] of a PrivateIdentifier to look up the PrivateName for a given scope. This corresponds closely to our implementation in the binder and checker: - we mangle PrivateIdentifier.escapedText to get a `key` which we use to get the symbol for a property f getLiteralTypeFromProperty-check privateIdentifier rename and simplify privateNameAndAny test case make it clearer that all this test is showing is that we allow accessing arbitrary private identifiers on `any`. Note: we could have something more sound here by checking that there is a private-named field declaration in a class scope above the property access. Discussion: https://github.com/microsoft/TypeScript/pull/30829/files#r302760015 Fix typo in checker s/identifer/identifier remove accidental change patch fourslash test broken by isPrivateIdentifier just needed to add a check to see if the symbol .name is defined extract reportUnmatchedProperty per @nsandersn feedback propertiesRelatedTo was getting to long pull out the unmatchedProperty reporting into a seprate function fix typo in private names test Fix type soundness with private names Remove PrivateIdentifier from emit with Expr hint Fixup helpers and set function name for privates remove accidentally-committed baselines These baselines somehow ended up in this pr, though they have nothing to do with the changes Revert "getLiteralTypeFromProperty-check privateIdentifier" This reverts commit bd1155c300bc3517a0543580f4790268f86e473f. reason: the check for isIdentifier in getLiteralTypeFromProperty is superfluous because we do this check in getLiteralTypeFromPropertyName Update comment in private name uniqueness test 3 I think the comments were not accurate and that we export the error on `this.#x = child.#x` because: - private names are lexically scoped: the code in question is not in a lexical scope under the definition of Child's #x. - private names are private to their containing class: never inherited This expected behavior matches that of Chrome Canary and my understanding of the spec test private names use before def, circular ref test private names use before def, circular ref update diagnosticMessages s/delete/'delete' per @DanielRosenwasser and @sandersn guidance, use this style in diagnostic messages: "operand of a 'delete' operator" (single quotes) rather than old style: "operand of a delete operator" (single quotes) This is for consistency, as we use the new style in the privateIdentifiers error messages and it is consistent with our messages about other operators incorporate private names early exit feedback and code style change to use a ternary instead of if so we can 'const' require private-named fields to be declared in JS All fields must be declared in TS files. In JS files, we typically do not have this requirement. So special-case private fields, which must always be declared (even in JS files, per spec) update debug failure for es2015 private identifier Co-Authored-By: Ron Buckton <ron.buckton@microsoft.com> fix checker handling of private name in subclasse update checker and tests to account for the following ts features: - private names do not participate in the prototype chain, but *are* assigned in the parent class' constructor. So parent can access its *own* private fields on instances of the subclass Add more tests for private-named fields in JS add test to hit symbolToExpression w private names symbolToExpression knows about private names add a test to exercise this code path ban private-named static methods (not supported yet) ban private-named methods (not supported yet) ban private-named accessors (not supported yet) fix privateIdentifier fourslash test change assertion throw to return Co-Authored-By: Ron Buckton <ron.buckton@microsoft.com> Update comment in checker.ts re reserved members Remove case for privateIdentifier in EntityNameExpr Remove case for privateIdentifier in EntityNameExpr. That code path is never hit, and privateIdnetifiers cannot be entity names. remove unnecessary parentheses Ban private identifier in enum As the new test, 'privateNameEnumNoEmit', shows, the checker now correctly makes a diagnostic for private identifiers in enums. However, when noEmit is false we hit this assertion in the transformer. This assertion will have to be removed so that we have a diagnostic here instead of an assertion error. When the assertion is removed, the 'privateNameEnum' baseline will have to be updated Fix destructuring assignment, use createCallBinding, remove unneeded helper Add class private field helpers to external helpers Remove private identifier enum assertion, use missing identifiers Fix hash map inefficiency by only using get Update baselines with empty identifier change Add privateNameEnum test baselines Fix private identifier destructuring (array assignment defaults, unique names) Use createPrivateIdentifierAssignment in destructuring transform Fix lint error Separate destructuring target visitor from regular visitor Fix destructuring assignment with this bindings Fix destructuring assignment with this bindings Fix syntax error with destructuring assignment output Disallow private identifiers in property signatures remove duplicate test baselines Add tests for undeclarated private identifiers remove unnecessary cast Nicer error message for mis-placed hashbang Workaround v8 bug with destructured assignments Optimize private identifier stack lookup Avoid the cost of performing an array lookup to look at the top of the private identifier environment stack. Change function name to be more specific Changes "getOperatorForCompoundAssignment" to "getNonAssignmentOperatorForCompoundAssignment" now that this function is accessible to the entire compiler. Improve test case for private name assignment Adds a compound assignment test case for a class with private names being declared on the left-hand-side of the assignment expression. Remove extra non-private-field test Remove isPrivateIdentifierAssignmentExpression helper Don't transform private names in ESNext target Preserve private fields initialized to functions Move function expressions to outer scope for efficiency Add WeakMap collision check Modify potential WeakMap collision condition Fix this property assignment binding with private names Add correct error message for WeakMap collision Add error for statements before super with private identifiers Refactor getPropertyForPrivateIdentifier Add test for private identifier fields initialized to class exprs Fix shebang errors Fix private errors on index signatures Add codefix for missing private property Update error messages for unsupported private features Fix inheritance-related errors Fixes inheritance-related errors with private identifiers by resolving properties from base classes. Private identifiers do not show up as properties on a union type, so those do not type-check. Add test for interface extending class with private access Remove debugging log Remove name assignment from private named functions Rename to getPrivateIdentifierPropertyOfType Fix index signature test comment Fix test target syntax error Change error messages patch private identifiers outside class bodies Add test for private identifier with ooo super Add test for a class with a private identifier with a non-preambly (for example, not a comment) statement before 'super': should error, saying 'super' must come first Fix nits incorporate PR feedback Incorporate checker feedback - reorganize if statements in checkFunctionOrConstructorSymbol - remove overload for getPrivateIdentifierPropertyOfType reorganize if statements in checkFunctionOrConstructorSymbol test for private names with JSX use getPropertyOftype in getPropertyForPrivateIdentifier getPrivateIdentifierPropertyOfType error on synthetic make getPrivateIdentifierPropertyOfType error if given a node that is not from the parse tree Simplify checkPrivateIdentifierPropertyAccess use getPropertiesOfType instead of rehashing that logic test for private identifiers w decl merging fix test target for privateNameDeclarationMerging update baselines Fix private identifier ++/-- numeric coercion Remove 'downleveled' from super error Fix bad comments in helper call emit Error on private identifiers in JSX tag names Add more private identifier tests Add es2015 target for private name destructured binding test Add privateNameConstructorSignature test Add test for navigation bar w private identifier Remove spurious line from test // in js file class A { exports.#foo = 3; // should error } The above line failed to produce an error when run using the test harness. When using tsc or the language server, we got the expected error message. Removing the troublesome line, as it seems to say more about the test runner than about the code it is testing. Fix inefficient constructor generation dts: don't emit type for private-identified field Do not emit types for private-identified fields when generating declaration files. // example.ts export class A { #foo: number; } // example.d.ts export declare class A { #foo; } **This is not ideal!** The following would be better: // example.d.ts export declare unique class A { #foo; } See discussion: https://github.com/microsoft/TypeScript/pull/33038#issuecomment-530321165 notice when private-identified field unused Notice when private-identified fields are unused, and implement the same behavior as for unused private-modified fields. This is used in the language server to make things grayed out. This case generates an error when --noUnusedLocals flag is passed to tsc: - "<name> is declared but never used" accept baselines Revert "dts: don't emit type for private-identified field" This reverts commit e50305df5fb88121486291abad14478f5339a455. Instead of just excluding the type from private identifier emit, only emit a single private identifier per class. This accomplishes nominality while hiding implementation detail that is irrelevant to .d.ts consumers only emit a single private identifier in dts In dts emit, emit at most one private identifier, and rename it to `#private`. refactor getPrivateIdentifierPropertyOfType - safer check for wehther is parse tree node - return undefined when not found (instead of a Debug.fail) Incorporate PR feedback Don't rely on parent pointers in transform Passes context about whether the postfix unary expression value is discarded down the tree into the visitPostfixUnaryExpression function. Remove orphaned test baseline files remove unreachable if Check `any`-typed private identified fields Update private identifier incompatible modifier checks - disallow 'abstract' with private identifiers - s/private-named-property/private identifier Add additional call expression test cases Fix disallow 'abstract' with private identifier Static private identifiers not inherited Including this in the PR for private instance fields even though static private identifiers are banned. Reason: this change improves quality of error messages, see test case. Thanks Ron! Simplifiy private identifier 'any' type handling Error on private identifier declarations for ES5/ES3 Bind `this` for private identifier property tagged template literals Fix target for jsdocPrivateName1 test Update getPrivateIdentifierPropertyOfType API Make it easier to use by accepting a string and location, rather than a PrivateIdentifier. Thanks Ron! remove orphaned tests rename test remove duplicate tests Remove unrelated error from test update diagnostic message 'private identifier' The nodes for hash private fields are now called 'private identifier'. Update one last diagnostic message to use the new terminology. refine solution for static private identifier fields - use `continue` instead of `filter` for perf - better naming - make it clear the current solution will need to be altered when we lift the ban on static private identifier fields, including a test case that should change in the future Fix display of private identifiers in lang server Fix bug where private identifiers in completion tooltips in the playground were showing up as the symbol table entries (with underscores and such). https://github.com/microsoft/TypeScript/pull/30829#issuecomment-534157560 Signed-off-by: Max Heiber <max.heiber@gmail.com> * fix privateIdentifier w !useDefineForClassFields Signed-off-by: Max Heiber <max.heiber@gmail.com> * Disallow PrivateIdentifier in Optional Chains Signed-off-by: Max Heiber <max.heiber@gmail.com> * restrict privateIdentifier completions correctly Don't autocomplete privateIdentifiers in places where they are not allowed. Signed-off-by: Max Heiber <max.heiber@gmail.com> * make PrivateIdentifier not a PropertyNameLiteral Signed-off-by: Max Heiber <max.heiber@gmail.com> * Added test. * Accepted baselines. * Update symbol serializer to understand private fields in JS `.d.ts` emit. * Accepted baselines. * fix for private field no initializer esnext Signed-off-by: Max Heiber <max.heiber@gmail.com> * fix private fields .d.ts emit for JS w expando fix bug where the following in a JS file would lead to a `#private` in the .d.ts: ```js class C { constructor () { this.a = 3 } } ``` Co-authored-by: Joey Watts <joey.watts.96@gmail.com> Co-authored-by: Daniel Rosenwasser <DanielRosenwasser@users.noreply.github.com>
2019-12-27 22:07:35 +01:00
export interface PrivateIdentifier {
readonly text: string;
}
export interface Symbol {
readonly name: string;
getFlags(): SymbolFlags;
getEscapedName(): __String;
getName(): string;
getDeclarations(): Declaration[] | undefined;
getDocumentationComment(typeChecker: TypeChecker | undefined): SymbolDisplayPart[];
/* @internal */
getContextualDocumentationComment(context: Node | undefined, checker: TypeChecker | undefined): SymbolDisplayPart[]
getJsDocTags(checker?: TypeChecker): JSDocTagInfo[];
}
export interface Type {
getFlags(): TypeFlags;
getSymbol(): Symbol | undefined;
getProperties(): Symbol[];
getProperty(propertyName: string): Symbol | undefined;
getApparentProperties(): Symbol[];
getCallSignatures(): readonly Signature[];
getConstructSignatures(): readonly Signature[];
getStringIndexType(): Type | undefined;
getNumberIndexType(): Type | undefined;
getBaseTypes(): BaseType[] | undefined;
getNonNullableType(): Type;
/*@internal*/ getNonOptionalType(): Type;
/*@internal*/ isNullableType(): boolean;
getConstraint(): Type | undefined;
getDefault(): Type | undefined;
isUnion(): this is UnionType;
isIntersection(): this is IntersectionType;
isUnionOrIntersection(): this is UnionOrIntersectionType;
isLiteral(): this is LiteralType;
isStringLiteral(): this is StringLiteralType;
isNumberLiteral(): this is NumberLiteralType;
isTypeParameter(): this is TypeParameter;
isClassOrInterface(): this is InterfaceType;
isClass(): this is InterfaceType;
}
export interface TypeReference {
typeArguments?: readonly Type[];
}
export interface Signature {
getDeclaration(): SignatureDeclaration;
getTypeParameters(): TypeParameter[] | undefined;
getParameters(): Symbol[];
getReturnType(): Type;
getDocumentationComment(typeChecker: TypeChecker | undefined): SymbolDisplayPart[];
getJsDocTags(): JSDocTagInfo[];
}
export interface SourceFile {
/* @internal */ version: string;
Enable '--strictNullChecks' (#22088) * Enable '--strictNullChecks' * Fix API baselines * Make sys.getEnvironmentVariable non-nullable * make properties optional instead of using `| undefined` in thier type * reportDiagnostics should be required * Declare firstAccessor as non-nullable * Make `some` a type guard * Fix `getEnvironmentVariable` definition in tests * Pretend transformFlags are always defined * Fix one more use of sys.getEnvironmentVariable * `requiredResponse` accepts undefined, remove assertions * Mark optional properties as optional instead of using `| undefined` * Mark optional properties as optional instead of using ` | undefined` * Remove unnecessary null assertions * Put the bang on the declaration instead of every use * Make `createMapFromTemplate` require a parameter * Mark `EmitResult.emittedFiles` and `EmitResult.sourceMaps` as optional * Plumb through undefined in emitLsit and EmitExpressionList * `ElementAccessExpression.argumentExpression` can not be `undefined` * Add overloads for `writeTokenText` * Make `shouldWriteSeparatingLineTerminator` argument non-nullable * Make `synthesizedNodeStartsOnNewLine` argument required * `PropertyAssignment.initializer` cannot be undefined * Use one `!` at declaration site instead of on every use site * Capture host in a constant and avoid null assertions * Remove few more unused assertions * Update baselines * Use parameter defaults * Update baselines * Fix lint * Make Symbol#valueDeclaration and Symbol#declarations non-optional to reduce assertions * Make Node#symbol and Type#symbol non-optional to reduce assertions * Make `flags` non-nullable to reduce assertions * Convert some asserts to type guards * Make `isNonLocalAlias` a type guard * Add overload for `getSymbolOfNode` for `Declaration` * Some more `getSymbolOfNode` changes * Push undefined suppression into `typeToTypeNodeHelper` * `NodeBuilderContext.tracker` is never `undefined` * use `Debug.assertDefined` * Remove unnecessary tag * Mark `LiteralType.freshType` and `LiteralTupe.regularType` as required
2018-05-22 23:46:57 +02:00
/* @internal */ scriptSnapshot: IScriptSnapshot | undefined;
/* @internal */ nameTable: UnderscoreEscapedMap<number> | undefined;
/* @internal */ getNamedDeclarations(): ESMap<string, readonly Declaration[]>;
getLineAndCharacterOfPosition(pos: number): LineAndCharacter;
getLineEndOfPosition(pos: number): number;
getLineStarts(): readonly number[];
getPositionOfLineAndCharacter(line: number, character: number): number;
update(newText: string, textChangeRange: TextChangeRange): SourceFile;
/* @internal */ sourceMapper?: DocumentPositionMapper;
}
export interface SourceFileLike {
getLineAndCharacterOfPosition(pos: number): LineAndCharacter;
}
export interface SourceMapSource {
getLineAndCharacterOfPosition(pos: number): LineAndCharacter;
}
/**
* Represents an immutable snapshot of a script at a specified time.Once acquired, the
* snapshot is observably immutable. i.e. the same calls with the same parameters will return
* the same values.
*/
// eslint-disable-next-line @typescript-eslint/naming-convention
export interface IScriptSnapshot {
/** Gets a portion of the script snapshot specified by [start, end). */
getText(start: number, end: number): string;
/** Gets the length of this script snapshot. */
getLength(): number;
/**
* Gets the TextChangeRange that describe how the text changed between this text and
* an older version. This information is used by the incremental parser to determine
* what sections of the script need to be re-parsed. 'undefined' can be returned if the
* change range cannot be determined. However, in that case, incremental parsing will
* not happen and the entire document will be re - parsed.
*/
getChangeRange(oldSnapshot: IScriptSnapshot): TextChangeRange | undefined;
/** Releases all resources held by this script snapshot */
dispose?(): void;
}
export namespace ScriptSnapshot {
class StringScriptSnapshot implements IScriptSnapshot {
constructor(private text: string) {
}
public getText(start: number, end: number): string {
return start === 0 && end === this.text.length
? this.text
: this.text.substring(start, end);
}
public getLength(): number {
return this.text.length;
}
Enable '--strictNullChecks' (#22088) * Enable '--strictNullChecks' * Fix API baselines * Make sys.getEnvironmentVariable non-nullable * make properties optional instead of using `| undefined` in thier type * reportDiagnostics should be required * Declare firstAccessor as non-nullable * Make `some` a type guard * Fix `getEnvironmentVariable` definition in tests * Pretend transformFlags are always defined * Fix one more use of sys.getEnvironmentVariable * `requiredResponse` accepts undefined, remove assertions * Mark optional properties as optional instead of using `| undefined` * Mark optional properties as optional instead of using ` | undefined` * Remove unnecessary null assertions * Put the bang on the declaration instead of every use * Make `createMapFromTemplate` require a parameter * Mark `EmitResult.emittedFiles` and `EmitResult.sourceMaps` as optional * Plumb through undefined in emitLsit and EmitExpressionList * `ElementAccessExpression.argumentExpression` can not be `undefined` * Add overloads for `writeTokenText` * Make `shouldWriteSeparatingLineTerminator` argument non-nullable * Make `synthesizedNodeStartsOnNewLine` argument required * `PropertyAssignment.initializer` cannot be undefined * Use one `!` at declaration site instead of on every use site * Capture host in a constant and avoid null assertions * Remove few more unused assertions * Update baselines * Use parameter defaults * Update baselines * Fix lint * Make Symbol#valueDeclaration and Symbol#declarations non-optional to reduce assertions * Make Node#symbol and Type#symbol non-optional to reduce assertions * Make `flags` non-nullable to reduce assertions * Convert some asserts to type guards * Make `isNonLocalAlias` a type guard * Add overload for `getSymbolOfNode` for `Declaration` * Some more `getSymbolOfNode` changes * Push undefined suppression into `typeToTypeNodeHelper` * `NodeBuilderContext.tracker` is never `undefined` * use `Debug.assertDefined` * Remove unnecessary tag * Mark `LiteralType.freshType` and `LiteralTupe.regularType` as required
2018-05-22 23:46:57 +02:00
public getChangeRange(): TextChangeRange | undefined {
// Text-based snapshots do not support incremental parsing. Return undefined
// to signal that to the caller.
return undefined;
}
}
export function fromString(text: string): IScriptSnapshot {
return new StringScriptSnapshot(text);
}
}
2018-05-03 20:00:10 +02:00
export interface PreProcessedFileInfo {
referencedFiles: FileReference[];
typeReferenceDirectives: FileReference[];
2018-05-03 20:00:10 +02:00
libReferenceDirectives: FileReference[];
importedFiles: FileReference[];
Enable '--strictNullChecks' (#22088) * Enable '--strictNullChecks' * Fix API baselines * Make sys.getEnvironmentVariable non-nullable * make properties optional instead of using `| undefined` in thier type * reportDiagnostics should be required * Declare firstAccessor as non-nullable * Make `some` a type guard * Fix `getEnvironmentVariable` definition in tests * Pretend transformFlags are always defined * Fix one more use of sys.getEnvironmentVariable * `requiredResponse` accepts undefined, remove assertions * Mark optional properties as optional instead of using `| undefined` * Mark optional properties as optional instead of using ` | undefined` * Remove unnecessary null assertions * Put the bang on the declaration instead of every use * Make `createMapFromTemplate` require a parameter * Mark `EmitResult.emittedFiles` and `EmitResult.sourceMaps` as optional * Plumb through undefined in emitLsit and EmitExpressionList * `ElementAccessExpression.argumentExpression` can not be `undefined` * Add overloads for `writeTokenText` * Make `shouldWriteSeparatingLineTerminator` argument non-nullable * Make `synthesizedNodeStartsOnNewLine` argument required * `PropertyAssignment.initializer` cannot be undefined * Use one `!` at declaration site instead of on every use site * Capture host in a constant and avoid null assertions * Remove few more unused assertions * Update baselines * Use parameter defaults * Update baselines * Fix lint * Make Symbol#valueDeclaration and Symbol#declarations non-optional to reduce assertions * Make Node#symbol and Type#symbol non-optional to reduce assertions * Make `flags` non-nullable to reduce assertions * Convert some asserts to type guards * Make `isNonLocalAlias` a type guard * Add overload for `getSymbolOfNode` for `Declaration` * Some more `getSymbolOfNode` changes * Push undefined suppression into `typeToTypeNodeHelper` * `NodeBuilderContext.tracker` is never `undefined` * use `Debug.assertDefined` * Remove unnecessary tag * Mark `LiteralType.freshType` and `LiteralTupe.regularType` as required
2018-05-22 23:46:57 +02:00
ambientExternalModules?: string[];
isLibFile: boolean;
}
export interface HostCancellationToken {
isCancellationRequested(): boolean;
}
export interface InstallPackageOptions {
fileName: Path;
packageName: string;
}
Updated: Only auto-import from package.json (#32517) * Move package.json related utils to utilities * Add failing test * Make first test pass * Don’t filter when there’s no package.json, fix scoped package imports * Use type acquisition as a heuristic for whether a JS project is using node core * Make same fix in getCompletionDetails * Fix re-exporting * Change JS node core module heuristic to same-file utilization * Remove unused method * Remove other unused method * Remove unused triple-slash ref * Update comment * Refactor findAlias to forEachAlias to reduce iterations * Really fix re-exporting * Use getModuleSpecifier instead of custom hack * Fix offering auto imports to paths within node modules * Rename things and make comments better * Add another reexport test * Inline `symbolHasBeenSeen` * Simplify forEachAlias to findAlias * Add note that symbols is mutated * Symbol order doesn’t matter here * Style nits * Add test with nested package.jsons * Fix and add tests for export * re-exports * Don’t fail when alias isn’t found * Make some easy optimizations * Clean up memoization when done * Remove unnecessary semicolon * Make getSymbolsFromOtherSourceFileExports pure * Cache auto imports * Revert "Cache auto imports" This reverts commit 8ea482958786aba0185b4b1b0497d6658ffbc385. * Handle merged symbols through cache * Be safer with symbol declarations, add logging * Improve cache invalidation for imports and exports * Check symbol presence first * Only run cache invalidation logic if there’s something to clear * Consolidate cache invalidation logic * Fix reuseProgramStructure test * Add more logging * Only clear cache if symbols are different * Refactor ambient module handling * Start caching package.json stuff * Support package.json searching in fourslash * Move import suggestions cache to Project * Start making more module specifier work available without having the importing file * Going to backtrack some from here * Get rid of dumb cache, fix node core modules stuff * Start determining changes to a file have invalidated its own auto imports * Move package.json related utils to utilities * Add failing test * Make first test pass * Don’t filter when there’s no package.json, fix scoped package imports * Use type acquisition as a heuristic for whether a JS project is using node core * Make same fix in getCompletionDetails * Fix re-exporting * Change JS node core module heuristic to same-file utilization * Remove unused method * Remove other unused method * Remove unused triple-slash ref * Update comment * Refactor findAlias to forEachAlias to reduce iterations * Really fix re-exporting * Use getModuleSpecifier instead of custom hack * Fix offering auto imports to paths within node modules * Rename things and make comments better * Add another reexport test * Inline `symbolHasBeenSeen` * Simplify forEachAlias to findAlias * Add note that symbols is mutated * Symbol order doesn’t matter here * Style nits * Add test with nested package.jsons * Fix and add tests for export * re-exports * Don’t fail when alias isn’t found * Make some easy optimizations * Clean up memoization when done * Remove unnecessary semicolon * Make getSymbolsFromOtherSourceFileExports pure * Cache auto imports * Revert "Cache auto imports" This reverts commit 8ea482958786aba0185b4b1b0497d6658ffbc385. * Handle merged symbols through cache * Be safer with symbol declarations, add logging * Improve cache invalidation for imports and exports * Check symbol presence first * Only run cache invalidation logic if there’s something to clear * Consolidate cache invalidation logic * Fix reuseProgramStructure test * Add more logging * Only clear cache if symbols are different * Refactor ambient module handling * Finish(?) sourceFileHasChangedOwnImportSuggestions * Make package.json info model better * Fix misplaced paren * Use file structure cache for package.json detection when possible * Revert unnecessary changes in moduleSpecifiers * Revert more unnecessary changes * Don’t watch package.jsons inside node_modules, fix tests * Work around declaration emit bug * Sync submodules? * Delete unused type * Add server cache tests * Fix server fourslash editing * Fix packageJsonInfo tests * Add node core modules cache test and fix more fourslash * Clean up symlink caching * Improve logging * Function name doesn’t make any sense anymore * Move symlinks cache to host * Fix markFileAsDirty from ScriptInfo * Mark new Project members internal * Use Path instead of fileName * Rename AutoImportSuggestionsCache * Improve WatchType description * Remove entries() from packageJsonCache * Fix path/fileName bug * Also cache symlinks on Program for benefit of d.ts emit * Let language service use Program’s symlink cache
2019-09-27 22:38:31 +02:00
/* @internal */
export const enum PackageJsonDependencyGroup {
Dependencies = 1 << 0,
DevDependencies = 1 << 1,
PeerDependencies = 1 << 2,
OptionalDependencies = 1 << 3,
All = Dependencies | DevDependencies | PeerDependencies | OptionalDependencies,
}
/* @internal */
export interface PackageJsonInfo {
fileName: string;
Expand auto-import to all package.json dependencies (#38923) * Start experiment * Add logging * Go back to a single program * Fix forEachExternalModuleToImportFrom * Move auxiliary program to language service * Add logging * Don’t use resolution cache * Fix(?) containingProjects for ScriptInfo in auxiliary program * Fix ScriptInfo project inclusion * Add test for default project of auto-importable ScriptInfo * Add fourslash server test * Don’t create auto import provider inside node_modules * Add monorepo-like test * WIP * Naively ensure autoImportProvider is up to date after package.json change * Start limiting when auto update provider gets updated * Respond to changes in node_modules * Don’t create auto-import provider until a file is open that would use it e.g., don’t create them during cross-project find-all-refs * Clean up naming, @internal marking, and fix empty project creation bug * Drop devDependencies, include peerDependencies * Add additional compiler options * Fix interaction with importSuggestionsCache * Move option to UserPreferences, allow inclusion of devDependencies * Don’t filter out peerDependencies * Watch unparseable package.jsons * But don’t filter packages out due to an invalid package.json * Update test * Don’t use autoImportProvider in codefixes where it can never be used (or any refactors) * Add CompletionEntry property for telemetry * Add assertion for isPackageJsonImport to fourslash * Fix missing pushSymbol argument * Add isPackageJsonImport to tests and API baselines * Fix unit test * Host auto import provider in new Project kind * Fix InferredProject attaching on AutoImportProvider-included files, load eagerly * Update Public APIs * Simplify PackageJsonCache host * Remove unneeded markAsDirty * Defer project finished event until after AutoImportProvider is created * Make AutoImportProviderProject always report isOrphan = true * Close and remove AutoImportProviderProject when host project closes * Don’t set pendingEnsureProjectForOpenFiles * Use hasAddedOrRemovedFiles instead of hasNewProgram * Use host-wide watchOptions for package.json watching * Add to `printProjects` * Clean up * Get autoImportProvider directly from LanguageServiceHost * Clean up * Clean up * Close auto import provider on disableLanguageService * Move AutoImportProvider preload to project updateGraph * Clear auto import suggestion cache when provider program changes * Fix tests * Revert yet-unneeded change * Use projectService host for module resolution host * Don’t re-resolve type directives if nothing has changed * Update src/server/project.ts Co-authored-by: Sheetal Nandi <shkamat@microsoft.com> * Use ts.emptyArray Co-authored-by: Sheetal Nandi <shkamat@microsoft.com>
2020-06-23 01:34:27 +02:00
parseable: boolean;
dependencies?: ESMap<string, string>;
devDependencies?: ESMap<string, string>;
peerDependencies?: ESMap<string, string>;
optionalDependencies?: ESMap<string, string>;
Updated: Only auto-import from package.json (#32517) * Move package.json related utils to utilities * Add failing test * Make first test pass * Don’t filter when there’s no package.json, fix scoped package imports * Use type acquisition as a heuristic for whether a JS project is using node core * Make same fix in getCompletionDetails * Fix re-exporting * Change JS node core module heuristic to same-file utilization * Remove unused method * Remove other unused method * Remove unused triple-slash ref * Update comment * Refactor findAlias to forEachAlias to reduce iterations * Really fix re-exporting * Use getModuleSpecifier instead of custom hack * Fix offering auto imports to paths within node modules * Rename things and make comments better * Add another reexport test * Inline `symbolHasBeenSeen` * Simplify forEachAlias to findAlias * Add note that symbols is mutated * Symbol order doesn’t matter here * Style nits * Add test with nested package.jsons * Fix and add tests for export * re-exports * Don’t fail when alias isn’t found * Make some easy optimizations * Clean up memoization when done * Remove unnecessary semicolon * Make getSymbolsFromOtherSourceFileExports pure * Cache auto imports * Revert "Cache auto imports" This reverts commit 8ea482958786aba0185b4b1b0497d6658ffbc385. * Handle merged symbols through cache * Be safer with symbol declarations, add logging * Improve cache invalidation for imports and exports * Check symbol presence first * Only run cache invalidation logic if there’s something to clear * Consolidate cache invalidation logic * Fix reuseProgramStructure test * Add more logging * Only clear cache if symbols are different * Refactor ambient module handling * Start caching package.json stuff * Support package.json searching in fourslash * Move import suggestions cache to Project * Start making more module specifier work available without having the importing file * Going to backtrack some from here * Get rid of dumb cache, fix node core modules stuff * Start determining changes to a file have invalidated its own auto imports * Move package.json related utils to utilities * Add failing test * Make first test pass * Don’t filter when there’s no package.json, fix scoped package imports * Use type acquisition as a heuristic for whether a JS project is using node core * Make same fix in getCompletionDetails * Fix re-exporting * Change JS node core module heuristic to same-file utilization * Remove unused method * Remove other unused method * Remove unused triple-slash ref * Update comment * Refactor findAlias to forEachAlias to reduce iterations * Really fix re-exporting * Use getModuleSpecifier instead of custom hack * Fix offering auto imports to paths within node modules * Rename things and make comments better * Add another reexport test * Inline `symbolHasBeenSeen` * Simplify forEachAlias to findAlias * Add note that symbols is mutated * Symbol order doesn’t matter here * Style nits * Add test with nested package.jsons * Fix and add tests for export * re-exports * Don’t fail when alias isn’t found * Make some easy optimizations * Clean up memoization when done * Remove unnecessary semicolon * Make getSymbolsFromOtherSourceFileExports pure * Cache auto imports * Revert "Cache auto imports" This reverts commit 8ea482958786aba0185b4b1b0497d6658ffbc385. * Handle merged symbols through cache * Be safer with symbol declarations, add logging * Improve cache invalidation for imports and exports * Check symbol presence first * Only run cache invalidation logic if there’s something to clear * Consolidate cache invalidation logic * Fix reuseProgramStructure test * Add more logging * Only clear cache if symbols are different * Refactor ambient module handling * Finish(?) sourceFileHasChangedOwnImportSuggestions * Make package.json info model better * Fix misplaced paren * Use file structure cache for package.json detection when possible * Revert unnecessary changes in moduleSpecifiers * Revert more unnecessary changes * Don’t watch package.jsons inside node_modules, fix tests * Work around declaration emit bug * Sync submodules? * Delete unused type * Add server cache tests * Fix server fourslash editing * Fix packageJsonInfo tests * Add node core modules cache test and fix more fourslash * Clean up symlink caching * Improve logging * Function name doesn’t make any sense anymore * Move symlinks cache to host * Fix markFileAsDirty from ScriptInfo * Mark new Project members internal * Use Path instead of fileName * Rename AutoImportSuggestionsCache * Improve WatchType description * Remove entries() from packageJsonCache * Fix path/fileName bug * Also cache symlinks on Program for benefit of d.ts emit * Let language service use Program’s symlink cache
2019-09-27 22:38:31 +02:00
get(dependencyName: string, inGroups?: PackageJsonDependencyGroup): string | undefined;
has(dependencyName: string, inGroups?: PackageJsonDependencyGroup): boolean;
}
Expand auto-import to all package.json dependencies (#38923) * Start experiment * Add logging * Go back to a single program * Fix forEachExternalModuleToImportFrom * Move auxiliary program to language service * Add logging * Don’t use resolution cache * Fix(?) containingProjects for ScriptInfo in auxiliary program * Fix ScriptInfo project inclusion * Add test for default project of auto-importable ScriptInfo * Add fourslash server test * Don’t create auto import provider inside node_modules * Add monorepo-like test * WIP * Naively ensure autoImportProvider is up to date after package.json change * Start limiting when auto update provider gets updated * Respond to changes in node_modules * Don’t create auto-import provider until a file is open that would use it e.g., don’t create them during cross-project find-all-refs * Clean up naming, @internal marking, and fix empty project creation bug * Drop devDependencies, include peerDependencies * Add additional compiler options * Fix interaction with importSuggestionsCache * Move option to UserPreferences, allow inclusion of devDependencies * Don’t filter out peerDependencies * Watch unparseable package.jsons * But don’t filter packages out due to an invalid package.json * Update test * Don’t use autoImportProvider in codefixes where it can never be used (or any refactors) * Add CompletionEntry property for telemetry * Add assertion for isPackageJsonImport to fourslash * Fix missing pushSymbol argument * Add isPackageJsonImport to tests and API baselines * Fix unit test * Host auto import provider in new Project kind * Fix InferredProject attaching on AutoImportProvider-included files, load eagerly * Update Public APIs * Simplify PackageJsonCache host * Remove unneeded markAsDirty * Defer project finished event until after AutoImportProvider is created * Make AutoImportProviderProject always report isOrphan = true * Close and remove AutoImportProviderProject when host project closes * Don’t set pendingEnsureProjectForOpenFiles * Use hasAddedOrRemovedFiles instead of hasNewProgram * Use host-wide watchOptions for package.json watching * Add to `printProjects` * Clean up * Get autoImportProvider directly from LanguageServiceHost * Clean up * Clean up * Close auto import provider on disableLanguageService * Move AutoImportProvider preload to project updateGraph * Clear auto import suggestion cache when provider program changes * Fix tests * Revert yet-unneeded change * Use projectService host for module resolution host * Don’t re-resolve type directives if nothing has changed * Update src/server/project.ts Co-authored-by: Sheetal Nandi <shkamat@microsoft.com> * Use ts.emptyArray Co-authored-by: Sheetal Nandi <shkamat@microsoft.com>
2020-06-23 01:34:27 +02:00
/* @internal */
export interface FormattingHost {
getNewLine?(): string;
}
Expand auto-import to all package.json dependencies (#38923) * Start experiment * Add logging * Go back to a single program * Fix forEachExternalModuleToImportFrom * Move auxiliary program to language service * Add logging * Don’t use resolution cache * Fix(?) containingProjects for ScriptInfo in auxiliary program * Fix ScriptInfo project inclusion * Add test for default project of auto-importable ScriptInfo * Add fourslash server test * Don’t create auto import provider inside node_modules * Add monorepo-like test * WIP * Naively ensure autoImportProvider is up to date after package.json change * Start limiting when auto update provider gets updated * Respond to changes in node_modules * Don’t create auto-import provider until a file is open that would use it e.g., don’t create them during cross-project find-all-refs * Clean up naming, @internal marking, and fix empty project creation bug * Drop devDependencies, include peerDependencies * Add additional compiler options * Fix interaction with importSuggestionsCache * Move option to UserPreferences, allow inclusion of devDependencies * Don’t filter out peerDependencies * Watch unparseable package.jsons * But don’t filter packages out due to an invalid package.json * Update test * Don’t use autoImportProvider in codefixes where it can never be used (or any refactors) * Add CompletionEntry property for telemetry * Add assertion for isPackageJsonImport to fourslash * Fix missing pushSymbol argument * Add isPackageJsonImport to tests and API baselines * Fix unit test * Host auto import provider in new Project kind * Fix InferredProject attaching on AutoImportProvider-included files, load eagerly * Update Public APIs * Simplify PackageJsonCache host * Remove unneeded markAsDirty * Defer project finished event until after AutoImportProvider is created * Make AutoImportProviderProject always report isOrphan = true * Close and remove AutoImportProviderProject when host project closes * Don’t set pendingEnsureProjectForOpenFiles * Use hasAddedOrRemovedFiles instead of hasNewProgram * Use host-wide watchOptions for package.json watching * Add to `printProjects` * Clean up * Get autoImportProvider directly from LanguageServiceHost * Clean up * Clean up * Close auto import provider on disableLanguageService * Move AutoImportProvider preload to project updateGraph * Clear auto import suggestion cache when provider program changes * Fix tests * Revert yet-unneeded change * Use projectService host for module resolution host * Don’t re-resolve type directives if nothing has changed * Update src/server/project.ts Co-authored-by: Sheetal Nandi <shkamat@microsoft.com> * Use ts.emptyArray Co-authored-by: Sheetal Nandi <shkamat@microsoft.com>
2020-06-23 01:34:27 +02:00
/* @internal */
export const enum PackageJsonAutoImportPreference {
Off,
On,
Auto,
Expand auto-import to all package.json dependencies (#38923) * Start experiment * Add logging * Go back to a single program * Fix forEachExternalModuleToImportFrom * Move auxiliary program to language service * Add logging * Don’t use resolution cache * Fix(?) containingProjects for ScriptInfo in auxiliary program * Fix ScriptInfo project inclusion * Add test for default project of auto-importable ScriptInfo * Add fourslash server test * Don’t create auto import provider inside node_modules * Add monorepo-like test * WIP * Naively ensure autoImportProvider is up to date after package.json change * Start limiting when auto update provider gets updated * Respond to changes in node_modules * Don’t create auto-import provider until a file is open that would use it e.g., don’t create them during cross-project find-all-refs * Clean up naming, @internal marking, and fix empty project creation bug * Drop devDependencies, include peerDependencies * Add additional compiler options * Fix interaction with importSuggestionsCache * Move option to UserPreferences, allow inclusion of devDependencies * Don’t filter out peerDependencies * Watch unparseable package.jsons * But don’t filter packages out due to an invalid package.json * Update test * Don’t use autoImportProvider in codefixes where it can never be used (or any refactors) * Add CompletionEntry property for telemetry * Add assertion for isPackageJsonImport to fourslash * Fix missing pushSymbol argument * Add isPackageJsonImport to tests and API baselines * Fix unit test * Host auto import provider in new Project kind * Fix InferredProject attaching on AutoImportProvider-included files, load eagerly * Update Public APIs * Simplify PackageJsonCache host * Remove unneeded markAsDirty * Defer project finished event until after AutoImportProvider is created * Make AutoImportProviderProject always report isOrphan = true * Close and remove AutoImportProviderProject when host project closes * Don’t set pendingEnsureProjectForOpenFiles * Use hasAddedOrRemovedFiles instead of hasNewProgram * Use host-wide watchOptions for package.json watching * Add to `printProjects` * Clean up * Get autoImportProvider directly from LanguageServiceHost * Clean up * Clean up * Close auto import provider on disableLanguageService * Move AutoImportProvider preload to project updateGraph * Clear auto import suggestion cache when provider program changes * Fix tests * Revert yet-unneeded change * Use projectService host for module resolution host * Don’t re-resolve type directives if nothing has changed * Update src/server/project.ts Co-authored-by: Sheetal Nandi <shkamat@microsoft.com> * Use ts.emptyArray Co-authored-by: Sheetal Nandi <shkamat@microsoft.com>
2020-06-23 01:34:27 +02:00
}
export interface PerformanceEvent {
kind: "UpdateGraph" | "CreatePackageJsonAutoImportProvider";
durationMs: number;
}
export enum LanguageServiceMode {
Semantic,
PartialSemantic,
Syntactic,
}
export interface IncompleteCompletionsCache {
get(): CompletionInfo | undefined;
set(response: CompletionInfo): void;
clear(): void;
}
//
// Public interface of the host of a language service instance.
//
export interface LanguageServiceHost extends GetEffectiveTypeRootsHost {
getCompilationSettings(): CompilerOptions;
getNewLine?(): string;
getProjectVersion?(): string;
getScriptFileNames(): string[];
getScriptKind?(fileName: string): ScriptKind;
getScriptVersion(fileName: string): string;
getScriptSnapshot(fileName: string): IScriptSnapshot | undefined;
getProjectReferences?(): readonly ProjectReference[] | undefined;
getLocalizedDiagnosticMessages?(): any;
getCancellationToken?(): HostCancellationToken;
getCurrentDirectory(): string;
getDefaultLibFileName(options: CompilerOptions): string;
log?(s: string): void;
trace?(s: string): void;
error?(s: string): void;
useCaseSensitiveFileNames?(): boolean;
/*
* LS host can optionally implement these methods to support completions for module specifiers.
* Without these methods, only completions for ambient modules will be provided.
*/
readDirectory?(path: string, extensions?: readonly string[], exclude?: readonly string[], include?: readonly string[], depth?: number): string[];
2017-07-14 23:26:13 +02:00
readFile?(path: string, encoding?: string): string | undefined;
realpath?(path: string): string;
fileExists?(path: string): boolean;
2016-09-27 23:02:10 +02:00
/*
* LS host can optionally implement these methods to support automatic updating when new type libraries are installed
*/
getTypeRootsVersion?(): number;
/*
* LS host can optionally implement this method if it wants to be completely in charge of module name resolution.
* if implementation is omitted then language service will use built-in module resolution logic and get answers to
* host specific questions using 'getScriptSnapshot'.
*
* If this is implemented, `getResolvedModuleWithFailedLookupLocationsFromCache` should be too.
*/
resolveModuleNames?(moduleNames: string[], containingFile: string, reusedNames: string[] | undefined, redirectedReference: ResolvedProjectReference | undefined, options: CompilerOptions, containingSourceFile?: SourceFile): (ResolvedModule | undefined)[];
getResolvedModuleWithFailedLookupLocationsFromCache?(modulename: string, containingFile: string, resolutionMode?: ModuleKind.CommonJS | ModuleKind.ESNext): ResolvedModuleWithFailedLookupLocations | undefined;
resolveTypeReferenceDirectives?(typeDirectiveNames: string[], containingFile: string, redirectedReference: ResolvedProjectReference | undefined, options: CompilerOptions): (ResolvedTypeReferenceDirective | undefined)[];
2017-10-03 04:08:13 +02:00
/* @internal */ hasInvalidatedResolution?: HasInvalidatedResolution;
/* @internal */ hasChangedAutomaticTypeDirectiveNames?: HasChangedAutomaticTypeDirectiveNames;
/* @internal */ getGlobalTypingsCacheLocation?(): string | undefined;
/* @internal */ getSymlinkCache?(files?: readonly SourceFile[]): SymlinkCache;
/*
* Required for full import and type reference completions.
* These should be unprefixed names. E.g. `getDirectories("/foo/bar")` should return `["a", "b"]`, not `["/foo/bar/a", "/foo/bar/b"]`.
*/
getDirectories?(directoryName: string): string[];
2017-02-07 23:36:15 +01:00
/**
* Gets a set of custom transformers to use during emit.
*/
getCustomTransformers?(): CustomTransformers | undefined;
isKnownTypesPackageName?(name: string): boolean;
installPackage?(options: InstallPackageOptions): Promise<ApplyCodeActionCommandResult>;
writeFile?(fileName: string, content: string): void;
/* @internal */ getDocumentPositionMapper?(generatedFileName: string, sourceFileName?: string): DocumentPositionMapper | undefined;
/* @internal */ getSourceFileLike?(fileName: string): SourceFileLike | undefined;
/* @internal */ getPackageJsonsVisibleToFile?(fileName: string, rootDir?: string): readonly PackageJsonInfo[];
/* @internal */ getNearestAncestorDirectoryWithPackageJson?(fileName: string): string | undefined;
/* @internal */ getPackageJsonsForAutoImport?(rootDir?: string): readonly PackageJsonInfo[];
/* @internal */ getCachedExportInfoMap?(): ExportInfoMap;
/* @internal */ getModuleSpecifierCache?(): ModuleSpecifierCache;
/* @internal */ setCompilerHost?(host: CompilerHost): void;
/* @internal */ useSourceOfProjectReferenceRedirect?(): boolean;
/* @internal */ getPackageJsonAutoImportProvider?(): Program | undefined;
/* @internal */ sendPerformanceEvent?(kind: PerformanceEvent["kind"], durationMs: number): void;
getParsedCommandLine?(fileName: string): ParsedCommandLine | undefined;
/* @internal */ onReleaseParsedCommandLine?(configFileName: string, oldResolvedRef: ResolvedProjectReference | undefined, optionOptions: CompilerOptions): void;
/* @internal */ getIncompleteCompletionsCache?(): IncompleteCompletionsCache;
}
/* @internal */
export const emptyOptions = {};
2018-11-07 03:45:08 +01:00
export type WithMetadata<T> = T & { metadata?: unknown; };
export const enum SemanticClassificationFormat {
Original = "original",
TwentyTwenty = "2020"
}
//
// Public services of a language service instance associated
// with a language service host instance
//
export interface LanguageService {
/** This is used as a part of restarting the language service. */
cleanupSemanticCache(): void;
/**
* Gets errors indicating invalid syntax in a file.
*
* In English, "this cdeo have, erorrs" is syntactically invalid because it has typos,
* grammatical errors, and misplaced punctuation. Likewise, examples of syntax
* errors in TypeScript are missing parentheses in an `if` statement, mismatched
* curly braces, and using a reserved keyword as a variable name.
*
* These diagnostics are inexpensive to compute and don't require knowledge of
* other files. Note that a non-empty result increases the likelihood of false positives
* from `getSemanticDiagnostics`.
*
* While these represent the majority of syntax-related diagnostics, there are some
* that require the type system, which will be present in `getSemanticDiagnostics`.
*
* @param fileName A path to the file you want syntactic diagnostics for
*/
getSyntacticDiagnostics(fileName: string): DiagnosticWithLocation[];
/**
* Gets warnings or errors indicating type system issues in a given file.
* Requesting semantic diagnostics may start up the type system and
* run deferred work, so the first call may take longer than subsequent calls.
*
* Unlike the other get*Diagnostics functions, these diagnostics can potentially not
* include a reference to a source file. Specifically, the first time this is called,
* it will return global diagnostics with no associated location.
*
* To contrast the differences between semantic and syntactic diagnostics, consider the
* sentence: "The sun is green." is syntactically correct; those are real English words with
* correct sentence structure. However, it is semantically invalid, because it is not true.
*
* @param fileName A path to the file you want semantic diagnostics for
*/
getSemanticDiagnostics(fileName: string): Diagnostic[];
/**
* Gets suggestion diagnostics for a specific file. These diagnostics tend to
* proactively suggest refactors, as opposed to diagnostics that indicate
* potentially incorrect runtime behavior.
*
* @param fileName A path to the file you want semantic diagnostics for
*/
getSuggestionDiagnostics(fileName: string): DiagnosticWithLocation[];
// TODO: Rename this to getProgramDiagnostics to better indicate that these are any
// diagnostics present for the program level, and not just 'options' diagnostics.
/**
* Gets global diagnostics related to the program configuration and compiler options.
*/
getCompilerOptionsDiagnostics(): Diagnostic[];
/** @deprecated Use getEncodedSyntacticClassifications instead. */
getSyntacticClassifications(fileName: string, span: TextSpan): ClassifiedSpan[];
getSyntacticClassifications(fileName: string, span: TextSpan, format: SemanticClassificationFormat): ClassifiedSpan[] | ClassifiedSpan2020[];
/** @deprecated Use getEncodedSemanticClassifications instead. */
getSemanticClassifications(fileName: string, span: TextSpan): ClassifiedSpan[];
getSemanticClassifications(fileName: string, span: TextSpan, format: SemanticClassificationFormat): ClassifiedSpan[] | ClassifiedSpan2020[];
/** Encoded as triples of [start, length, ClassificationType]. */
getEncodedSyntacticClassifications(fileName: string, span: TextSpan): Classifications;
/**
* Gets semantic highlights information for a particular file. Has two formats, an older
* version used by VS and a format used by VS Code.
*
* @param fileName The path to the file
* @param position A text span to return results within
* @param format Which format to use, defaults to "original"
* @returns a number array encoded as triples of [start, length, ClassificationType, ...].
*/
getEncodedSemanticClassifications(fileName: string, span: TextSpan, format?: SemanticClassificationFormat): Classifications;
/**
* Gets completion entries at a particular position in a file.
*
* @param fileName The path to the file
* @param position A zero-based index of the character where you want the entries
* @param options An object describing how the request was triggered and what kinds
* of code actions can be returned with the completions.
2021-11-16 01:39:52 +01:00
* @param formattingSettings settings needed for calling formatting functions.
*/
2021-11-16 01:39:52 +01:00
getCompletionsAtPosition(fileName: string, position: number, options: GetCompletionsAtPositionOptions | undefined, formattingSettings?: FormatCodeSettings): WithMetadata<CompletionInfo> | undefined;
/**
* Gets the extended details for a completion entry retrieved from `getCompletionsAtPosition`.
*
* @param fileName The path to the file
* @param position A zero based index of the character where you want the entries
* @param entryName The `name` from an existing completion which came from `getCompletionsAtPosition`
* @param formatOptions How should code samples in the completions be formatted, can be undefined for backwards compatibility
* @param source `source` property from the completion entry
* @param preferences User settings, can be undefined for backwards compatibility
* @param data `data` property from the completion entry
*/
getCompletionEntryDetails(
fileName: string,
position: number,
entryName: string,
formatOptions: FormatCodeOptions | FormatCodeSettings | undefined,
source: string | undefined,
preferences: UserPreferences | undefined,
data: CompletionEntryData | undefined,
Enable '--strictNullChecks' (#22088) * Enable '--strictNullChecks' * Fix API baselines * Make sys.getEnvironmentVariable non-nullable * make properties optional instead of using `| undefined` in thier type * reportDiagnostics should be required * Declare firstAccessor as non-nullable * Make `some` a type guard * Fix `getEnvironmentVariable` definition in tests * Pretend transformFlags are always defined * Fix one more use of sys.getEnvironmentVariable * `requiredResponse` accepts undefined, remove assertions * Mark optional properties as optional instead of using `| undefined` * Mark optional properties as optional instead of using ` | undefined` * Remove unnecessary null assertions * Put the bang on the declaration instead of every use * Make `createMapFromTemplate` require a parameter * Mark `EmitResult.emittedFiles` and `EmitResult.sourceMaps` as optional * Plumb through undefined in emitLsit and EmitExpressionList * `ElementAccessExpression.argumentExpression` can not be `undefined` * Add overloads for `writeTokenText` * Make `shouldWriteSeparatingLineTerminator` argument non-nullable * Make `synthesizedNodeStartsOnNewLine` argument required * `PropertyAssignment.initializer` cannot be undefined * Use one `!` at declaration site instead of on every use site * Capture host in a constant and avoid null assertions * Remove few more unused assertions * Update baselines * Use parameter defaults * Update baselines * Fix lint * Make Symbol#valueDeclaration and Symbol#declarations non-optional to reduce assertions * Make Node#symbol and Type#symbol non-optional to reduce assertions * Make `flags` non-nullable to reduce assertions * Convert some asserts to type guards * Make `isNonLocalAlias` a type guard * Add overload for `getSymbolOfNode` for `Declaration` * Some more `getSymbolOfNode` changes * Push undefined suppression into `typeToTypeNodeHelper` * `NodeBuilderContext.tracker` is never `undefined` * use `Debug.assertDefined` * Remove unnecessary tag * Mark `LiteralType.freshType` and `LiteralTupe.regularType` as required
2018-05-22 23:46:57 +02:00
): CompletionEntryDetails | undefined;
Enable '--strictNullChecks' (#22088) * Enable '--strictNullChecks' * Fix API baselines * Make sys.getEnvironmentVariable non-nullable * make properties optional instead of using `| undefined` in thier type * reportDiagnostics should be required * Declare firstAccessor as non-nullable * Make `some` a type guard * Fix `getEnvironmentVariable` definition in tests * Pretend transformFlags are always defined * Fix one more use of sys.getEnvironmentVariable * `requiredResponse` accepts undefined, remove assertions * Mark optional properties as optional instead of using `| undefined` * Mark optional properties as optional instead of using ` | undefined` * Remove unnecessary null assertions * Put the bang on the declaration instead of every use * Make `createMapFromTemplate` require a parameter * Mark `EmitResult.emittedFiles` and `EmitResult.sourceMaps` as optional * Plumb through undefined in emitLsit and EmitExpressionList * `ElementAccessExpression.argumentExpression` can not be `undefined` * Add overloads for `writeTokenText` * Make `shouldWriteSeparatingLineTerminator` argument non-nullable * Make `synthesizedNodeStartsOnNewLine` argument required * `PropertyAssignment.initializer` cannot be undefined * Use one `!` at declaration site instead of on every use site * Capture host in a constant and avoid null assertions * Remove few more unused assertions * Update baselines * Use parameter defaults * Update baselines * Fix lint * Make Symbol#valueDeclaration and Symbol#declarations non-optional to reduce assertions * Make Node#symbol and Type#symbol non-optional to reduce assertions * Make `flags` non-nullable to reduce assertions * Convert some asserts to type guards * Make `isNonLocalAlias` a type guard * Add overload for `getSymbolOfNode` for `Declaration` * Some more `getSymbolOfNode` changes * Push undefined suppression into `typeToTypeNodeHelper` * `NodeBuilderContext.tracker` is never `undefined` * use `Debug.assertDefined` * Remove unnecessary tag * Mark `LiteralType.freshType` and `LiteralTupe.regularType` as required
2018-05-22 23:46:57 +02:00
getCompletionEntrySymbol(fileName: string, position: number, name: string, source: string | undefined): Symbol | undefined;
/**
* Gets semantic information about the identifier at a particular position in a
* file. Quick info is what you typically see when you hover in an editor.
*
* @param fileName The path to the file
* @param position A zero-based index of the character where you want the quick info
*/
Enable '--strictNullChecks' (#22088) * Enable '--strictNullChecks' * Fix API baselines * Make sys.getEnvironmentVariable non-nullable * make properties optional instead of using `| undefined` in thier type * reportDiagnostics should be required * Declare firstAccessor as non-nullable * Make `some` a type guard * Fix `getEnvironmentVariable` definition in tests * Pretend transformFlags are always defined * Fix one more use of sys.getEnvironmentVariable * `requiredResponse` accepts undefined, remove assertions * Mark optional properties as optional instead of using `| undefined` * Mark optional properties as optional instead of using ` | undefined` * Remove unnecessary null assertions * Put the bang on the declaration instead of every use * Make `createMapFromTemplate` require a parameter * Mark `EmitResult.emittedFiles` and `EmitResult.sourceMaps` as optional * Plumb through undefined in emitLsit and EmitExpressionList * `ElementAccessExpression.argumentExpression` can not be `undefined` * Add overloads for `writeTokenText` * Make `shouldWriteSeparatingLineTerminator` argument non-nullable * Make `synthesizedNodeStartsOnNewLine` argument required * `PropertyAssignment.initializer` cannot be undefined * Use one `!` at declaration site instead of on every use site * Capture host in a constant and avoid null assertions * Remove few more unused assertions * Update baselines * Use parameter defaults * Update baselines * Fix lint * Make Symbol#valueDeclaration and Symbol#declarations non-optional to reduce assertions * Make Node#symbol and Type#symbol non-optional to reduce assertions * Make `flags` non-nullable to reduce assertions * Convert some asserts to type guards * Make `isNonLocalAlias` a type guard * Add overload for `getSymbolOfNode` for `Declaration` * Some more `getSymbolOfNode` changes * Push undefined suppression into `typeToTypeNodeHelper` * `NodeBuilderContext.tracker` is never `undefined` * use `Debug.assertDefined` * Remove unnecessary tag * Mark `LiteralType.freshType` and `LiteralTupe.regularType` as required
2018-05-22 23:46:57 +02:00
getQuickInfoAtPosition(fileName: string, position: number): QuickInfo | undefined;
Enable '--strictNullChecks' (#22088) * Enable '--strictNullChecks' * Fix API baselines * Make sys.getEnvironmentVariable non-nullable * make properties optional instead of using `| undefined` in thier type * reportDiagnostics should be required * Declare firstAccessor as non-nullable * Make `some` a type guard * Fix `getEnvironmentVariable` definition in tests * Pretend transformFlags are always defined * Fix one more use of sys.getEnvironmentVariable * `requiredResponse` accepts undefined, remove assertions * Mark optional properties as optional instead of using `| undefined` * Mark optional properties as optional instead of using ` | undefined` * Remove unnecessary null assertions * Put the bang on the declaration instead of every use * Make `createMapFromTemplate` require a parameter * Mark `EmitResult.emittedFiles` and `EmitResult.sourceMaps` as optional * Plumb through undefined in emitLsit and EmitExpressionList * `ElementAccessExpression.argumentExpression` can not be `undefined` * Add overloads for `writeTokenText` * Make `shouldWriteSeparatingLineTerminator` argument non-nullable * Make `synthesizedNodeStartsOnNewLine` argument required * `PropertyAssignment.initializer` cannot be undefined * Use one `!` at declaration site instead of on every use site * Capture host in a constant and avoid null assertions * Remove few more unused assertions * Update baselines * Use parameter defaults * Update baselines * Fix lint * Make Symbol#valueDeclaration and Symbol#declarations non-optional to reduce assertions * Make Node#symbol and Type#symbol non-optional to reduce assertions * Make `flags` non-nullable to reduce assertions * Convert some asserts to type guards * Make `isNonLocalAlias` a type guard * Add overload for `getSymbolOfNode` for `Declaration` * Some more `getSymbolOfNode` changes * Push undefined suppression into `typeToTypeNodeHelper` * `NodeBuilderContext.tracker` is never `undefined` * use `Debug.assertDefined` * Remove unnecessary tag * Mark `LiteralType.freshType` and `LiteralTupe.regularType` as required
2018-05-22 23:46:57 +02:00
getNameOrDottedNameSpan(fileName: string, startPos: number, endPos: number): TextSpan | undefined;
Enable '--strictNullChecks' (#22088) * Enable '--strictNullChecks' * Fix API baselines * Make sys.getEnvironmentVariable non-nullable * make properties optional instead of using `| undefined` in thier type * reportDiagnostics should be required * Declare firstAccessor as non-nullable * Make `some` a type guard * Fix `getEnvironmentVariable` definition in tests * Pretend transformFlags are always defined * Fix one more use of sys.getEnvironmentVariable * `requiredResponse` accepts undefined, remove assertions * Mark optional properties as optional instead of using `| undefined` * Mark optional properties as optional instead of using ` | undefined` * Remove unnecessary null assertions * Put the bang on the declaration instead of every use * Make `createMapFromTemplate` require a parameter * Mark `EmitResult.emittedFiles` and `EmitResult.sourceMaps` as optional * Plumb through undefined in emitLsit and EmitExpressionList * `ElementAccessExpression.argumentExpression` can not be `undefined` * Add overloads for `writeTokenText` * Make `shouldWriteSeparatingLineTerminator` argument non-nullable * Make `synthesizedNodeStartsOnNewLine` argument required * `PropertyAssignment.initializer` cannot be undefined * Use one `!` at declaration site instead of on every use site * Capture host in a constant and avoid null assertions * Remove few more unused assertions * Update baselines * Use parameter defaults * Update baselines * Fix lint * Make Symbol#valueDeclaration and Symbol#declarations non-optional to reduce assertions * Make Node#symbol and Type#symbol non-optional to reduce assertions * Make `flags` non-nullable to reduce assertions * Convert some asserts to type guards * Make `isNonLocalAlias` a type guard * Add overload for `getSymbolOfNode` for `Declaration` * Some more `getSymbolOfNode` changes * Push undefined suppression into `typeToTypeNodeHelper` * `NodeBuilderContext.tracker` is never `undefined` * use `Debug.assertDefined` * Remove unnecessary tag * Mark `LiteralType.freshType` and `LiteralTupe.regularType` as required
2018-05-22 23:46:57 +02:00
getBreakpointStatementAtPosition(fileName: string, position: number): TextSpan | undefined;
getSignatureHelpItems(fileName: string, position: number, options: SignatureHelpItemsOptions | undefined): SignatureHelpItems | undefined;
getRenameInfo(fileName: string, position: number, options?: RenameInfoOptions): RenameInfo;
findRenameLocations(fileName: string, position: number, findInStrings: boolean, findInComments: boolean, providePrefixAndSuffixTextForRename?: boolean): readonly RenameLocation[] | undefined;
2019-04-19 01:23:06 +02:00
getSmartSelectionRange(fileName: string, position: number): SelectionRange;
2019-04-12 02:32:40 +02:00
getDefinitionAtPosition(fileName: string, position: number): readonly DefinitionInfo[] | undefined;
Enable '--strictNullChecks' (#22088) * Enable '--strictNullChecks' * Fix API baselines * Make sys.getEnvironmentVariable non-nullable * make properties optional instead of using `| undefined` in thier type * reportDiagnostics should be required * Declare firstAccessor as non-nullable * Make `some` a type guard * Fix `getEnvironmentVariable` definition in tests * Pretend transformFlags are always defined * Fix one more use of sys.getEnvironmentVariable * `requiredResponse` accepts undefined, remove assertions * Mark optional properties as optional instead of using `| undefined` * Mark optional properties as optional instead of using ` | undefined` * Remove unnecessary null assertions * Put the bang on the declaration instead of every use * Make `createMapFromTemplate` require a parameter * Mark `EmitResult.emittedFiles` and `EmitResult.sourceMaps` as optional * Plumb through undefined in emitLsit and EmitExpressionList * `ElementAccessExpression.argumentExpression` can not be `undefined` * Add overloads for `writeTokenText` * Make `shouldWriteSeparatingLineTerminator` argument non-nullable * Make `synthesizedNodeStartsOnNewLine` argument required * `PropertyAssignment.initializer` cannot be undefined * Use one `!` at declaration site instead of on every use site * Capture host in a constant and avoid null assertions * Remove few more unused assertions * Update baselines * Use parameter defaults * Update baselines * Fix lint * Make Symbol#valueDeclaration and Symbol#declarations non-optional to reduce assertions * Make Node#symbol and Type#symbol non-optional to reduce assertions * Make `flags` non-nullable to reduce assertions * Convert some asserts to type guards * Make `isNonLocalAlias` a type guard * Add overload for `getSymbolOfNode` for `Declaration` * Some more `getSymbolOfNode` changes * Push undefined suppression into `typeToTypeNodeHelper` * `NodeBuilderContext.tracker` is never `undefined` * use `Debug.assertDefined` * Remove unnecessary tag * Mark `LiteralType.freshType` and `LiteralTupe.regularType` as required
2018-05-22 23:46:57 +02:00
getDefinitionAndBoundSpan(fileName: string, position: number): DefinitionInfoAndBoundSpan | undefined;
getTypeDefinitionAtPosition(fileName: string, position: number): readonly DefinitionInfo[] | undefined;
getImplementationAtPosition(fileName: string, position: number): readonly ImplementationLocation[] | undefined;
Enable '--strictNullChecks' (#22088) * Enable '--strictNullChecks' * Fix API baselines * Make sys.getEnvironmentVariable non-nullable * make properties optional instead of using `| undefined` in thier type * reportDiagnostics should be required * Declare firstAccessor as non-nullable * Make `some` a type guard * Fix `getEnvironmentVariable` definition in tests * Pretend transformFlags are always defined * Fix one more use of sys.getEnvironmentVariable * `requiredResponse` accepts undefined, remove assertions * Mark optional properties as optional instead of using `| undefined` * Mark optional properties as optional instead of using ` | undefined` * Remove unnecessary null assertions * Put the bang on the declaration instead of every use * Make `createMapFromTemplate` require a parameter * Mark `EmitResult.emittedFiles` and `EmitResult.sourceMaps` as optional * Plumb through undefined in emitLsit and EmitExpressionList * `ElementAccessExpression.argumentExpression` can not be `undefined` * Add overloads for `writeTokenText` * Make `shouldWriteSeparatingLineTerminator` argument non-nullable * Make `synthesizedNodeStartsOnNewLine` argument required * `PropertyAssignment.initializer` cannot be undefined * Use one `!` at declaration site instead of on every use site * Capture host in a constant and avoid null assertions * Remove few more unused assertions * Update baselines * Use parameter defaults * Update baselines * Fix lint * Make Symbol#valueDeclaration and Symbol#declarations non-optional to reduce assertions * Make Node#symbol and Type#symbol non-optional to reduce assertions * Make `flags` non-nullable to reduce assertions * Convert some asserts to type guards * Make `isNonLocalAlias` a type guard * Add overload for `getSymbolOfNode` for `Declaration` * Some more `getSymbolOfNode` changes * Push undefined suppression into `typeToTypeNodeHelper` * `NodeBuilderContext.tracker` is never `undefined` * use `Debug.assertDefined` * Remove unnecessary tag * Mark `LiteralType.freshType` and `LiteralTupe.regularType` as required
2018-05-22 23:46:57 +02:00
getReferencesAtPosition(fileName: string, position: number): ReferenceEntry[] | undefined;
findReferences(fileName: string, position: number): ReferencedSymbol[] | undefined;
getDocumentHighlights(fileName: string, position: number, filesToSearch: string[]): DocumentHighlights[] | undefined;
getFileReferences(fileName: string): ReferenceEntry[];
/** @deprecated */
getOccurrencesAtPosition(fileName: string, position: number): readonly ReferenceEntry[] | undefined;
2016-09-27 19:22:41 +02:00
getNavigateToItems(searchValue: string, maxResultCount?: number, fileName?: string, excludeDtsFiles?: boolean): NavigateToItem[];
getNavigationBarItems(fileName: string): NavigationBarItem[];
getNavigationTree(fileName: string): NavigationTree;
prepareCallHierarchy(fileName: string, position: number): CallHierarchyItem | CallHierarchyItem[] | undefined;
provideCallHierarchyIncomingCalls(fileName: string, position: number): CallHierarchyIncomingCall[];
provideCallHierarchyOutgoingCalls(fileName: string, position: number): CallHierarchyOutgoingCall[];
Add inlay hints support (#42089) * Add signature arguments label support * Support rest parameters and destruction * make lint * Fix tuple rest parameters * Adjust name styles * Rename to inline hints * Partition inline hints * Adjust range pred * Add function expression like hints * Support configure inline hints * Display hints in single line * Add test suits and tests * Add range tests * Support more hints * Add more options * Fix logical * Add more cases * Support call chains * Rename options * Match lastest protocol * Update protocol changes * Support context value and hover message * Revert "Support context value and hover message" This reverts commit 37a70896337ddd6dd5360d20e7001ed2338a2595. * Revert "Update protocol changes" This reverts commit e5ca31bc30362144c52c1c2512abc553f0c6b869. * Add hover message * Accept baseline * Update src/services/inlineHints.ts Co-authored-by: Daniel Rosenwasser <DanielRosenwasser@users.noreply.github.com> * Update src/services/inlineHints.ts Co-authored-by: Daniel Rosenwasser <DanielRosenwasser@users.noreply.github.com> * Cache across the program * Fix possible undefined * Update protocol changes * Fix missing property * Make lint happy * Avoid call chain hints * I'm bad * Add whitespace before type * Add more tests * Should care about jsdoc * Support complex rest parameter * Avoid module symbol hints * Care about leading comments * Fix CR issues * Avoid changes * Simplify comments contains * Fix CR issues * Accept baseline * Check parameter name before create regex * Rename option * Avoid makers * Skip parens for argument * Fix CR issues * Fix enums * Accept baseline Co-authored-by: Daniel Rosenwasser <DanielRosenwasser@users.noreply.github.com>
2021-06-25 08:06:34 +02:00
provideInlayHints(fileName: string, span: TextSpan, preferences: UserPreferences | undefined): InlayHint[]
getOutliningSpans(fileName: string): OutliningSpan[];
getTodoComments(fileName: string, descriptors: TodoCommentDescriptor[]): TodoComment[];
getBraceMatchingAtPosition(fileName: string, position: number): TextSpan[];
2016-09-27 19:22:41 +02:00
getIndentationAtPosition(fileName: string, position: number, options: EditorOptions | EditorSettings): number;
2016-09-27 19:22:41 +02:00
getFormattingEditsForRange(fileName: string, start: number, end: number, options: FormatCodeOptions | FormatCodeSettings): TextChange[];
getFormattingEditsForDocument(fileName: string, options: FormatCodeOptions | FormatCodeSettings): TextChange[];
getFormattingEditsAfterKeystroke(fileName: string, position: number, key: string, options: FormatCodeOptions | FormatCodeSettings): TextChange[];
getDocCommentTemplateAtPosition(fileName: string, position: number, options?: DocCommentTemplateOptions): TextInsertion | undefined;
isValidBraceCompletionAtPosition(fileName: string, position: number, openingBrace: number): boolean;
/**
* This will return a defined result if the position is after the `>` of the opening tag, or somewhere in the text, of a JSXElement with no closing tag.
* Editors should call this after `>` is typed.
*/
getJsxClosingTagAtPosition(fileName: string, position: number): JsxClosingTagInfo | undefined;
Enable '--strictNullChecks' (#22088) * Enable '--strictNullChecks' * Fix API baselines * Make sys.getEnvironmentVariable non-nullable * make properties optional instead of using `| undefined` in thier type * reportDiagnostics should be required * Declare firstAccessor as non-nullable * Make `some` a type guard * Fix `getEnvironmentVariable` definition in tests * Pretend transformFlags are always defined * Fix one more use of sys.getEnvironmentVariable * `requiredResponse` accepts undefined, remove assertions * Mark optional properties as optional instead of using `| undefined` * Mark optional properties as optional instead of using ` | undefined` * Remove unnecessary null assertions * Put the bang on the declaration instead of every use * Make `createMapFromTemplate` require a parameter * Mark `EmitResult.emittedFiles` and `EmitResult.sourceMaps` as optional * Plumb through undefined in emitLsit and EmitExpressionList * `ElementAccessExpression.argumentExpression` can not be `undefined` * Add overloads for `writeTokenText` * Make `shouldWriteSeparatingLineTerminator` argument non-nullable * Make `synthesizedNodeStartsOnNewLine` argument required * `PropertyAssignment.initializer` cannot be undefined * Use one `!` at declaration site instead of on every use site * Capture host in a constant and avoid null assertions * Remove few more unused assertions * Update baselines * Use parameter defaults * Update baselines * Fix lint * Make Symbol#valueDeclaration and Symbol#declarations non-optional to reduce assertions * Make Node#symbol and Type#symbol non-optional to reduce assertions * Make `flags` non-nullable to reduce assertions * Convert some asserts to type guards * Make `isNonLocalAlias` a type guard * Add overload for `getSymbolOfNode` for `Declaration` * Some more `getSymbolOfNode` changes * Push undefined suppression into `typeToTypeNodeHelper` * `NodeBuilderContext.tracker` is never `undefined` * use `Debug.assertDefined` * Remove unnecessary tag * Mark `LiteralType.freshType` and `LiteralTupe.regularType` as required
2018-05-22 23:46:57 +02:00
getSpanOfEnclosingComment(fileName: string, position: number, onlyMultiLine: boolean): TextSpan | undefined;
2018-05-08 00:12:50 +02:00
toLineColumnOffset?(fileName: string, position: number): LineAndCharacter;
/** @internal */
getSourceMapper(): SourceMapper;
/** @internal */
clearSourceMapperCache(): void;
2018-05-08 00:12:50 +02:00
getCodeFixesAtPosition(fileName: string, start: number, end: number, errorCodes: readonly number[], formatOptions: FormatCodeSettings, preferences: UserPreferences): readonly CodeFixAction[];
getCombinedCodeFix(scope: CombinedCodeFixScope, fixId: {}, formatOptions: FormatCodeSettings, preferences: UserPreferences): CombinedCodeActions;
2019-06-20 10:47:12 +02:00
applyCodeActionCommand(action: CodeActionCommand, formatSettings?: FormatCodeSettings): Promise<ApplyCodeActionCommandResult>;
applyCodeActionCommand(action: CodeActionCommand[], formatSettings?: FormatCodeSettings): Promise<ApplyCodeActionCommandResult[]>;
applyCodeActionCommand(action: CodeActionCommand | CodeActionCommand[], formatSettings?: FormatCodeSettings): Promise<ApplyCodeActionCommandResult | ApplyCodeActionCommandResult[]>;
/** @deprecated `fileName` will be ignored */
applyCodeActionCommand(fileName: string, action: CodeActionCommand): Promise<ApplyCodeActionCommandResult>;
/** @deprecated `fileName` will be ignored */
applyCodeActionCommand(fileName: string, action: CodeActionCommand[]): Promise<ApplyCodeActionCommandResult[]>;
/** @deprecated `fileName` will be ignored */
applyCodeActionCommand(fileName: string, action: CodeActionCommand | CodeActionCommand[]): Promise<ApplyCodeActionCommandResult | ApplyCodeActionCommandResult[]>;
2019-06-20 10:47:12 +02:00
getApplicableRefactors(fileName: string, positionOrRange: number | TextRange, preferences: UserPreferences | undefined, triggerReason?: RefactorTriggerReason, kind?: string): ApplicableRefactorInfo[];
getEditsForRefactor(fileName: string, formatOptions: FormatCodeSettings, positionOrRange: number | TextRange, refactorName: string, actionName: string, preferences: UserPreferences | undefined): RefactorEditInfo | undefined;
organizeImports(args: OrganizeImportsArgs, formatOptions: FormatCodeSettings, preferences: UserPreferences | undefined): readonly FileTextChanges[];
getEditsForFileRename(oldFilePath: string, newFilePath: string, formatOptions: FormatCodeSettings, preferences: UserPreferences | undefined): readonly FileTextChanges[];
getEmitOutput(fileName: string, emitOnlyDtsFiles?: boolean, forceDtsEmit?: boolean): EmitOutput;
Enable '--strictNullChecks' (#22088) * Enable '--strictNullChecks' * Fix API baselines * Make sys.getEnvironmentVariable non-nullable * make properties optional instead of using `| undefined` in thier type * reportDiagnostics should be required * Declare firstAccessor as non-nullable * Make `some` a type guard * Fix `getEnvironmentVariable` definition in tests * Pretend transformFlags are always defined * Fix one more use of sys.getEnvironmentVariable * `requiredResponse` accepts undefined, remove assertions * Mark optional properties as optional instead of using `| undefined` * Mark optional properties as optional instead of using ` | undefined` * Remove unnecessary null assertions * Put the bang on the declaration instead of every use * Make `createMapFromTemplate` require a parameter * Mark `EmitResult.emittedFiles` and `EmitResult.sourceMaps` as optional * Plumb through undefined in emitLsit and EmitExpressionList * `ElementAccessExpression.argumentExpression` can not be `undefined` * Add overloads for `writeTokenText` * Make `shouldWriteSeparatingLineTerminator` argument non-nullable * Make `synthesizedNodeStartsOnNewLine` argument required * `PropertyAssignment.initializer` cannot be undefined * Use one `!` at declaration site instead of on every use site * Capture host in a constant and avoid null assertions * Remove few more unused assertions * Update baselines * Use parameter defaults * Update baselines * Fix lint * Make Symbol#valueDeclaration and Symbol#declarations non-optional to reduce assertions * Make Node#symbol and Type#symbol non-optional to reduce assertions * Make `flags` non-nullable to reduce assertions * Convert some asserts to type guards * Make `isNonLocalAlias` a type guard * Add overload for `getSymbolOfNode` for `Declaration` * Some more `getSymbolOfNode` changes * Push undefined suppression into `typeToTypeNodeHelper` * `NodeBuilderContext.tracker` is never `undefined` * use `Debug.assertDefined` * Remove unnecessary tag * Mark `LiteralType.freshType` and `LiteralTupe.regularType` as required
2018-05-22 23:46:57 +02:00
getProgram(): Program | undefined;
/* @internal */ getNonBoundSourceFile(fileName: string): SourceFile;
Expand auto-import to all package.json dependencies (#38923) * Start experiment * Add logging * Go back to a single program * Fix forEachExternalModuleToImportFrom * Move auxiliary program to language service * Add logging * Don’t use resolution cache * Fix(?) containingProjects for ScriptInfo in auxiliary program * Fix ScriptInfo project inclusion * Add test for default project of auto-importable ScriptInfo * Add fourslash server test * Don’t create auto import provider inside node_modules * Add monorepo-like test * WIP * Naively ensure autoImportProvider is up to date after package.json change * Start limiting when auto update provider gets updated * Respond to changes in node_modules * Don’t create auto-import provider until a file is open that would use it e.g., don’t create them during cross-project find-all-refs * Clean up naming, @internal marking, and fix empty project creation bug * Drop devDependencies, include peerDependencies * Add additional compiler options * Fix interaction with importSuggestionsCache * Move option to UserPreferences, allow inclusion of devDependencies * Don’t filter out peerDependencies * Watch unparseable package.jsons * But don’t filter packages out due to an invalid package.json * Update test * Don’t use autoImportProvider in codefixes where it can never be used (or any refactors) * Add CompletionEntry property for telemetry * Add assertion for isPackageJsonImport to fourslash * Fix missing pushSymbol argument * Add isPackageJsonImport to tests and API baselines * Fix unit test * Host auto import provider in new Project kind * Fix InferredProject attaching on AutoImportProvider-included files, load eagerly * Update Public APIs * Simplify PackageJsonCache host * Remove unneeded markAsDirty * Defer project finished event until after AutoImportProvider is created * Make AutoImportProviderProject always report isOrphan = true * Close and remove AutoImportProviderProject when host project closes * Don’t set pendingEnsureProjectForOpenFiles * Use hasAddedOrRemovedFiles instead of hasNewProgram * Use host-wide watchOptions for package.json watching * Add to `printProjects` * Clean up * Get autoImportProvider directly from LanguageServiceHost * Clean up * Clean up * Close auto import provider on disableLanguageService * Move AutoImportProvider preload to project updateGraph * Clear auto import suggestion cache when provider program changes * Fix tests * Revert yet-unneeded change * Use projectService host for module resolution host * Don’t re-resolve type directives if nothing has changed * Update src/server/project.ts Co-authored-by: Sheetal Nandi <shkamat@microsoft.com> * Use ts.emptyArray Co-authored-by: Sheetal Nandi <shkamat@microsoft.com>
2020-06-23 01:34:27 +02:00
/* @internal */ getAutoImportProvider(): Program | undefined;
2020-07-10 03:35:54 +02:00
toggleLineComment(fileName: string, textRange: TextRange): TextChange[];
toggleMultilineComment(fileName: string, textRange: TextRange): TextChange[];
commentSelection(fileName: string, textRange: TextRange): TextChange[];
uncommentSelection(fileName: string, textRange: TextRange): TextChange[];
dispose(): void;
}
export interface JsxClosingTagInfo {
readonly newText: string;
}
export interface CombinedCodeFixScope { type: "file"; fileName: string; }
export interface OrganizeImportsArgs extends CombinedCodeFixScope {
skipDestructiveCodeActions?: boolean;
}
Import statement completions (#43149) * WIP * WIP * Get completion details working * Start unifying eager and lazy auto imports * Fix export= * Fix completion details for totally misspelled names * Almost fixed duplication... * Fix remaining completion tests * Refactor to support multiple origins for same symbol * Make import fixes make slightly more sense * Add cache back in * Set insertText based on import kind * Update API baselines * Add semicolons, snippet support, and sourceDisplay * Add some tests * Update baselines * Fix pattern ambient modules appearing in auto imports * Fix tests * Remove commented code * Switch to valueDeclaration for getting module source file * Small optimizations * Cache module specifiers / importableness and export map separately * Fix and test cache invalidation logic * Update API baselines * Add separate user preference for snippet-formatted completions * Require first character to match when resolving module specifiers * Fix AutoImportProvider export map cache invalidation * Really fix auto import provider export map invalidation * Update test added in master * Use logical or assignment Co-authored-by: Daniel Rosenwasser <DanielRosenwasser@users.noreply.github.com> * Simply conditional by reversing Co-authored-by: Daniel Rosenwasser <DanielRosenwasser@users.noreply.github.com> * When file is deleted need to marked correctly in the project as removed file * Simplify hasAddedOrRemovedSymlinks with cherry-picked fix * Ensure replacement range is on one line * Update baselines Co-authored-by: Daniel Rosenwasser <DanielRosenwasser@users.noreply.github.com> Co-authored-by: Sheetal Nandi <shkamat@microsoft.com>
2021-03-26 22:47:07 +01:00
export type CompletionsTriggerCharacter = "." | '"' | "'" | "`" | "/" | "@" | "<" | "#" | " ";
export const enum CompletionTriggerKind {
/** Completion was triggered by typing an identifier, manual invocation (e.g Ctrl+Space) or via API. */
Invoked = 1,
/** Completion was triggered by a trigger character. */
TriggerCharacter = 2,
/** Completion was re-triggered as the current completion list is incomplete. */
TriggerForIncompleteCompletions = 3,
}
export interface GetCompletionsAtPositionOptions extends UserPreferences {
/**
* If the editor is asking for completions because a certain character was typed
* (as opposed to when the user explicitly requested them) this should be set.
*/
triggerCharacter?: CompletionsTriggerCharacter;
triggerKind?: CompletionTriggerKind;
/** @deprecated Use includeCompletionsForModuleExports */
includeExternalModuleExports?: boolean;
/** @deprecated Use includeCompletionsWithInsertText */
includeInsertTextCompletions?: boolean;
}
Add inlay hints support (#42089) * Add signature arguments label support * Support rest parameters and destruction * make lint * Fix tuple rest parameters * Adjust name styles * Rename to inline hints * Partition inline hints * Adjust range pred * Add function expression like hints * Support configure inline hints * Display hints in single line * Add test suits and tests * Add range tests * Support more hints * Add more options * Fix logical * Add more cases * Support call chains * Rename options * Match lastest protocol * Update protocol changes * Support context value and hover message * Revert "Support context value and hover message" This reverts commit 37a70896337ddd6dd5360d20e7001ed2338a2595. * Revert "Update protocol changes" This reverts commit e5ca31bc30362144c52c1c2512abc553f0c6b869. * Add hover message * Accept baseline * Update src/services/inlineHints.ts Co-authored-by: Daniel Rosenwasser <DanielRosenwasser@users.noreply.github.com> * Update src/services/inlineHints.ts Co-authored-by: Daniel Rosenwasser <DanielRosenwasser@users.noreply.github.com> * Cache across the program * Fix possible undefined * Update protocol changes * Fix missing property * Make lint happy * Avoid call chain hints * I'm bad * Add whitespace before type * Add more tests * Should care about jsdoc * Support complex rest parameter * Avoid module symbol hints * Care about leading comments * Fix CR issues * Avoid changes * Simplify comments contains * Fix CR issues * Accept baseline * Check parameter name before create regex * Rename option * Avoid makers * Skip parens for argument * Fix CR issues * Fix enums * Accept baseline Co-authored-by: Daniel Rosenwasser <DanielRosenwasser@users.noreply.github.com>
2021-06-25 08:06:34 +02:00
export interface InlayHintsOptions extends UserPreferences {
readonly includeInlayParameterNameHints?: "none" | "literals" | "all";
readonly includeInlayParameterNameHintsWhenArgumentMatchesName?: boolean;
readonly includeInlayFunctionParameterTypeHints?: boolean,
readonly includeInlayVariableTypeHints?: boolean;
readonly includeInlayPropertyDeclarationTypeHints?: boolean;
readonly includeInlayFunctionLikeReturnTypeHints?: boolean;
readonly includeInlayEnumMemberValueHints?: boolean;
}
export type SignatureHelpTriggerCharacter = "," | "(" | "<";
export type SignatureHelpRetriggerCharacter = SignatureHelpTriggerCharacter | ")";
export interface SignatureHelpItemsOptions {
triggerReason?: SignatureHelpTriggerReason;
}
export type SignatureHelpTriggerReason =
| SignatureHelpInvokedReason
| SignatureHelpCharacterTypedReason
| SignatureHelpRetriggeredReason;
/**
* Signals that the user manually requested signature help.
* The language service will unconditionally attempt to provide a result.
*/
export interface SignatureHelpInvokedReason {
2018-07-03 01:40:08 +02:00
kind: "invoked";
triggerCharacter?: undefined;
}
/**
* Signals that the signature help request came from a user typing a character.
* Depending on the character and the syntactic context, the request may or may not be served a result.
*/
export interface SignatureHelpCharacterTypedReason {
2018-07-03 01:40:08 +02:00
kind: "characterTyped";
/**
* Character that was responsible for triggering signature help.
*/
2018-07-03 01:40:08 +02:00
triggerCharacter: SignatureHelpTriggerCharacter;
}
/**
* Signals that this signature help request came from typing a character or moving the cursor.
* This should only occur if a signature help session was already active and the editor needs to see if it should adjust.
* The language service will unconditionally attempt to provide a result.
* `triggerCharacter` can be `undefined` for a retrigger caused by a cursor move.
*/
export interface SignatureHelpRetriggeredReason {
2018-07-03 01:40:08 +02:00
kind: "retrigger";
/**
* Character that was responsible for triggering signature help.
*/
2018-07-03 01:40:08 +02:00
triggerCharacter?: SignatureHelpRetriggerCharacter;
}
export interface ApplyCodeActionCommandResult {
successMessage: string;
}
export interface Classifications {
spans: number[];
endOfLineState: EndOfLineState;
}
export interface ClassifiedSpan {
textSpan: TextSpan;
classificationType: ClassificationTypeNames;
}
export interface ClassifiedSpan2020 {
textSpan: TextSpan;
classificationType: number;
}
/**
* Navigation bar interface designed for visual studio's dual-column layout.
* This does not form a proper tree.
* The navbar is returned as a list of top-level items, each of which has a list of child items.
* Child items always have an empty array for their `childItems`.
*/
export interface NavigationBarItem {
text: string;
kind: ScriptElementKind;
kindModifiers: string;
spans: TextSpan[];
childItems: NavigationBarItem[];
indent: number;
bolded: boolean;
grayed: boolean;
}
/**
* Node in a tree of nested declarations in a file.
* The top node is always a script or module node.
*/
export interface NavigationTree {
/** Name of the declaration, or a short description, e.g. "<class>". */
text: string;
kind: ScriptElementKind;
/** ScriptElementKindModifier separated by commas, e.g. "public,abstract" */
kindModifiers: string;
/**
* Spans of the nodes that generated this declaration.
* There will be more than one if this is the result of merging.
*/
spans: TextSpan[];
nameSpan: TextSpan | undefined;
/** Present if non-empty */
childItems?: NavigationTree[];
}
export interface CallHierarchyItem {
name: string;
kind: ScriptElementKind;
kindModifiers?: string;
file: string;
span: TextSpan;
selectionSpan: TextSpan;
containerName?: string;
}
export interface CallHierarchyIncomingCall {
from: CallHierarchyItem;
fromSpans: TextSpan[];
}
export interface CallHierarchyOutgoingCall {
to: CallHierarchyItem;
fromSpans: TextSpan[];
}
Add inlay hints support (#42089) * Add signature arguments label support * Support rest parameters and destruction * make lint * Fix tuple rest parameters * Adjust name styles * Rename to inline hints * Partition inline hints * Adjust range pred * Add function expression like hints * Support configure inline hints * Display hints in single line * Add test suits and tests * Add range tests * Support more hints * Add more options * Fix logical * Add more cases * Support call chains * Rename options * Match lastest protocol * Update protocol changes * Support context value and hover message * Revert "Support context value and hover message" This reverts commit 37a70896337ddd6dd5360d20e7001ed2338a2595. * Revert "Update protocol changes" This reverts commit e5ca31bc30362144c52c1c2512abc553f0c6b869. * Add hover message * Accept baseline * Update src/services/inlineHints.ts Co-authored-by: Daniel Rosenwasser <DanielRosenwasser@users.noreply.github.com> * Update src/services/inlineHints.ts Co-authored-by: Daniel Rosenwasser <DanielRosenwasser@users.noreply.github.com> * Cache across the program * Fix possible undefined * Update protocol changes * Fix missing property * Make lint happy * Avoid call chain hints * I'm bad * Add whitespace before type * Add more tests * Should care about jsdoc * Support complex rest parameter * Avoid module symbol hints * Care about leading comments * Fix CR issues * Avoid changes * Simplify comments contains * Fix CR issues * Accept baseline * Check parameter name before create regex * Rename option * Avoid makers * Skip parens for argument * Fix CR issues * Fix enums * Accept baseline Co-authored-by: Daniel Rosenwasser <DanielRosenwasser@users.noreply.github.com>
2021-06-25 08:06:34 +02:00
export const enum InlayHintKind {
Type = "Type",
Parameter = "Parameter",
Enum = "Enum",
}
export interface InlayHint {
text: string;
position: number;
kind: InlayHintKind;
Add inlay hints support (#42089) * Add signature arguments label support * Support rest parameters and destruction * make lint * Fix tuple rest parameters * Adjust name styles * Rename to inline hints * Partition inline hints * Adjust range pred * Add function expression like hints * Support configure inline hints * Display hints in single line * Add test suits and tests * Add range tests * Support more hints * Add more options * Fix logical * Add more cases * Support call chains * Rename options * Match lastest protocol * Update protocol changes * Support context value and hover message * Revert "Support context value and hover message" This reverts commit 37a70896337ddd6dd5360d20e7001ed2338a2595. * Revert "Update protocol changes" This reverts commit e5ca31bc30362144c52c1c2512abc553f0c6b869. * Add hover message * Accept baseline * Update src/services/inlineHints.ts Co-authored-by: Daniel Rosenwasser <DanielRosenwasser@users.noreply.github.com> * Update src/services/inlineHints.ts Co-authored-by: Daniel Rosenwasser <DanielRosenwasser@users.noreply.github.com> * Cache across the program * Fix possible undefined * Update protocol changes * Fix missing property * Make lint happy * Avoid call chain hints * I'm bad * Add whitespace before type * Add more tests * Should care about jsdoc * Support complex rest parameter * Avoid module symbol hints * Care about leading comments * Fix CR issues * Avoid changes * Simplify comments contains * Fix CR issues * Accept baseline * Check parameter name before create regex * Rename option * Avoid makers * Skip parens for argument * Fix CR issues * Fix enums * Accept baseline Co-authored-by: Daniel Rosenwasser <DanielRosenwasser@users.noreply.github.com>
2021-06-25 08:06:34 +02:00
whitespaceBefore?: boolean;
whitespaceAfter?: boolean;
}
export interface TodoCommentDescriptor {
text: string;
priority: number;
}
export interface TodoComment {
descriptor: TodoCommentDescriptor;
message: string;
position: number;
}
export interface TextChange {
span: TextSpan;
newText: string;
}
export interface FileTextChanges {
fileName: string;
textChanges: readonly TextChange[];
isNewFile?: boolean;
}
2016-10-06 22:59:54 +02:00
export interface CodeAction {
/** Description of the code action to display in the UI of the editor */
description: string;
/** Text changes to apply to each file as part of the code action */
changes: FileTextChanges[];
/**
* If the user accepts the code fix, the editor should send the action back in a `applyAction` request.
* This allows the language service to have side effects (e.g. installing dependencies) upon a code fix.
*/
commands?: CodeActionCommand[];
}
export interface CodeFixAction extends CodeAction {
/** Short name to identify the fix, for use by telemetry. */
fixName: string;
/**
* If present, one may call 'getCombinedCodeFix' with this fixId.
* This may be omitted to indicate that the code fix can't be applied in a group.
*/
fixId?: {};
fixAllDescription?: string;
}
export interface CombinedCodeActions {
changes: readonly FileTextChanges[];
commands?: readonly CodeActionCommand[];
}
// Publicly, this type is just `{}`. Internally it is a union of all the actions we use.
// See `commands?: {}[]` in protocol.ts
2019-04-23 22:51:47 +02:00
export type CodeActionCommand = InstallPackageAction;
export interface InstallPackageAction {
/* @internal */ readonly type: "install package";
/* @internal */ readonly file: string;
/* @internal */ readonly packageName: string;
}
2017-06-06 23:58:18 +02:00
/**
* A set of one or more available refactoring actions, grouped under a parent refactoring.
*/
2017-05-19 19:18:42 +02:00
export interface ApplicableRefactorInfo {
2017-06-06 23:58:18 +02:00
/**
* The programmatic name of the refactoring
*/
2017-05-19 19:18:42 +02:00
name: string;
2017-06-06 23:58:18 +02:00
/**
* A description of this refactoring category to show to the user.
* If the refactoring gets inlined (see below), this text will not be visible.
*/
2017-05-19 19:18:42 +02:00
description: string;
2017-06-06 23:58:18 +02:00
/**
* Inlineable refactorings can have their actions hoisted out to the top level
* of a context menu. Non-inlineanable refactorings should always be shown inside
* their parent grouping.
*
* If not specified, this value is assumed to be 'true'
*/
inlineable?: boolean;
actions: RefactorActionInfo[];
2017-05-19 19:18:42 +02:00
}
2017-06-06 23:58:18 +02:00
/**
* Represents a single refactoring action - for example, the "Extract Method..." refactor might
* offer several actions, each corresponding to a surround class or closure to extract into.
*/
export interface RefactorActionInfo {
2017-06-06 23:58:18 +02:00
/**
* The programmatic name of the refactoring action
*/
name: string;
/**
* A description of this refactoring action to show to the user.
* If the parent refactoring is inlined away, this will be the only text shown,
* so this description should make sense by itself if the parent is inlineable=true
*/
description: string;
/**
* A message to show to the user if the refactoring cannot be applied in
* the current context.
*/
notApplicableReason?: string;
/**
* The hierarchical dotted name of the refactor action.
*/
kind?: string;
}
2017-06-06 23:58:18 +02:00
/**
* A set of edits to make in response to a refactor action, plus an optional
* location where renaming should be invoked from
*/
export interface RefactorEditInfo {
2017-06-06 23:58:18 +02:00
edits: FileTextChanges[];
Enable '--strictNullChecks' (#22088) * Enable '--strictNullChecks' * Fix API baselines * Make sys.getEnvironmentVariable non-nullable * make properties optional instead of using `| undefined` in thier type * reportDiagnostics should be required * Declare firstAccessor as non-nullable * Make `some` a type guard * Fix `getEnvironmentVariable` definition in tests * Pretend transformFlags are always defined * Fix one more use of sys.getEnvironmentVariable * `requiredResponse` accepts undefined, remove assertions * Mark optional properties as optional instead of using `| undefined` * Mark optional properties as optional instead of using ` | undefined` * Remove unnecessary null assertions * Put the bang on the declaration instead of every use * Make `createMapFromTemplate` require a parameter * Mark `EmitResult.emittedFiles` and `EmitResult.sourceMaps` as optional * Plumb through undefined in emitLsit and EmitExpressionList * `ElementAccessExpression.argumentExpression` can not be `undefined` * Add overloads for `writeTokenText` * Make `shouldWriteSeparatingLineTerminator` argument non-nullable * Make `synthesizedNodeStartsOnNewLine` argument required * `PropertyAssignment.initializer` cannot be undefined * Use one `!` at declaration site instead of on every use site * Capture host in a constant and avoid null assertions * Remove few more unused assertions * Update baselines * Use parameter defaults * Update baselines * Fix lint * Make Symbol#valueDeclaration and Symbol#declarations non-optional to reduce assertions * Make Node#symbol and Type#symbol non-optional to reduce assertions * Make `flags` non-nullable to reduce assertions * Convert some asserts to type guards * Make `isNonLocalAlias` a type guard * Add overload for `getSymbolOfNode` for `Declaration` * Some more `getSymbolOfNode` changes * Push undefined suppression into `typeToTypeNodeHelper` * `NodeBuilderContext.tracker` is never `undefined` * use `Debug.assertDefined` * Remove unnecessary tag * Mark `LiteralType.freshType` and `LiteralTupe.regularType` as required
2018-05-22 23:46:57 +02:00
renameFilename?: string ;
renameLocation?: number;
commands?: CodeActionCommand[];
}
2017-06-06 23:58:18 +02:00
2020-05-22 01:08:19 +02:00
export type RefactorTriggerReason = "implicit" | "invoked";
2020-04-14 22:17:19 +02:00
export interface TextInsertion {
newText: string;
/** The position in newText the caret should point to after the insertion. */
caretOffset: number;
}
export interface DocumentSpan {
textSpan: TextSpan;
fileName: string;
/**
* If the span represents a location that was remapped (e.g. via a .d.ts.map file),
* then the original filename and span will be specified here
*/
originalTextSpan?: TextSpan;
originalFileName?: string;
/**
* If DocumentSpan.textSpan is the span for name of the declaration,
* then this is the span for relevant declaration
*/
2019-06-13 21:25:02 +02:00
contextSpan?: TextSpan;
originalContextSpan?: TextSpan;
}
export interface RenameLocation extends DocumentSpan {
readonly prefixText?: string;
readonly suffixText?: string;
}
export interface ReferenceEntry extends DocumentSpan {
isWriteAccess: boolean;
isDefinition: boolean;
isInString?: true;
}
export interface ImplementationLocation extends DocumentSpan {
kind: ScriptElementKind;
displayParts: SymbolDisplayPart[];
}
export const enum HighlightSpanKind {
none = "none",
definition = "definition",
reference = "reference",
writtenReference = "writtenReference",
}
export interface HighlightSpan {
fileName?: string;
isInString?: true;
textSpan: TextSpan;
2019-06-13 21:25:02 +02:00
contextSpan?: TextSpan;
kind: HighlightSpanKind;
}
export interface NavigateToItem {
name: string;
kind: ScriptElementKind;
kindModifiers: string;
matchKind: "exact" | "prefix" | "substring" | "camelCase";
isCaseSensitive: boolean;
fileName: string;
textSpan: TextSpan;
containerName: string;
containerKind: ScriptElementKind;
}
2016-09-27 19:22:41 +02:00
export enum IndentStyle {
None = 0,
Block = 1,
Smart = 2,
}
export enum SemicolonPreference {
Ignore = "ignore",
Insert = "insert",
Remove = "remove",
}
2016-09-27 19:22:41 +02:00
/* @deprecated - consider using EditorSettings instead */
export interface EditorOptions {
BaseIndentSize?: number;
IndentSize: number;
TabSize: number;
NewLineCharacter: string;
ConvertTabsToSpaces: boolean;
IndentStyle: IndentStyle;
}
Enable '--strictNullChecks' (#22088) * Enable '--strictNullChecks' * Fix API baselines * Make sys.getEnvironmentVariable non-nullable * make properties optional instead of using `| undefined` in thier type * reportDiagnostics should be required * Declare firstAccessor as non-nullable * Make `some` a type guard * Fix `getEnvironmentVariable` definition in tests * Pretend transformFlags are always defined * Fix one more use of sys.getEnvironmentVariable * `requiredResponse` accepts undefined, remove assertions * Mark optional properties as optional instead of using `| undefined` * Mark optional properties as optional instead of using ` | undefined` * Remove unnecessary null assertions * Put the bang on the declaration instead of every use * Make `createMapFromTemplate` require a parameter * Mark `EmitResult.emittedFiles` and `EmitResult.sourceMaps` as optional * Plumb through undefined in emitLsit and EmitExpressionList * `ElementAccessExpression.argumentExpression` can not be `undefined` * Add overloads for `writeTokenText` * Make `shouldWriteSeparatingLineTerminator` argument non-nullable * Make `synthesizedNodeStartsOnNewLine` argument required * `PropertyAssignment.initializer` cannot be undefined * Use one `!` at declaration site instead of on every use site * Capture host in a constant and avoid null assertions * Remove few more unused assertions * Update baselines * Use parameter defaults * Update baselines * Fix lint * Make Symbol#valueDeclaration and Symbol#declarations non-optional to reduce assertions * Make Node#symbol and Type#symbol non-optional to reduce assertions * Make `flags` non-nullable to reduce assertions * Convert some asserts to type guards * Make `isNonLocalAlias` a type guard * Add overload for `getSymbolOfNode` for `Declaration` * Some more `getSymbolOfNode` changes * Push undefined suppression into `typeToTypeNodeHelper` * `NodeBuilderContext.tracker` is never `undefined` * use `Debug.assertDefined` * Remove unnecessary tag * Mark `LiteralType.freshType` and `LiteralTupe.regularType` as required
2018-05-22 23:46:57 +02:00
// TODO: GH#18217 These are frequently asserted as defined
2016-09-27 19:22:41 +02:00
export interface EditorSettings {
baseIndentSize?: number;
indentSize?: number;
tabSize?: number;
newLineCharacter?: string;
convertTabsToSpaces?: boolean;
indentStyle?: IndentStyle;
trimTrailingWhitespace?: boolean;
}
2016-09-27 19:22:41 +02:00
/* @deprecated - consider using FormatCodeSettings instead */
export interface FormatCodeOptions extends EditorOptions {
InsertSpaceAfterCommaDelimiter: boolean;
InsertSpaceAfterSemicolonInForStatements: boolean;
InsertSpaceBeforeAndAfterBinaryOperators: boolean;
InsertSpaceAfterConstructor?: boolean;
InsertSpaceAfterKeywordsInControlFlowStatements: boolean;
InsertSpaceAfterFunctionKeywordForAnonymousFunctions: boolean;
InsertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis: boolean;
InsertSpaceAfterOpeningAndBeforeClosingNonemptyBrackets: boolean;
InsertSpaceAfterOpeningAndBeforeClosingNonemptyBraces?: boolean;
InsertSpaceAfterOpeningAndBeforeClosingTemplateStringBraces: boolean;
InsertSpaceAfterOpeningAndBeforeClosingJsxExpressionBraces?: boolean;
InsertSpaceAfterTypeAssertion?: boolean;
InsertSpaceBeforeFunctionParenthesis?: boolean;
PlaceOpenBraceOnNewLineForFunctions: boolean;
PlaceOpenBraceOnNewLineForControlBlocks: boolean;
insertSpaceBeforeTypeAnnotation?: boolean;
2016-09-27 19:22:41 +02:00
}
export interface FormatCodeSettings extends EditorSettings {
readonly insertSpaceAfterCommaDelimiter?: boolean;
readonly insertSpaceAfterSemicolonInForStatements?: boolean;
readonly insertSpaceBeforeAndAfterBinaryOperators?: boolean;
readonly insertSpaceAfterConstructor?: boolean;
readonly insertSpaceAfterKeywordsInControlFlowStatements?: boolean;
readonly insertSpaceAfterFunctionKeywordForAnonymousFunctions?: boolean;
readonly insertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis?: boolean;
readonly insertSpaceAfterOpeningAndBeforeClosingNonemptyBrackets?: boolean;
readonly insertSpaceAfterOpeningAndBeforeClosingNonemptyBraces?: boolean;
readonly insertSpaceAfterOpeningAndBeforeClosingEmptyBraces?: boolean;
readonly insertSpaceAfterOpeningAndBeforeClosingTemplateStringBraces?: boolean;
readonly insertSpaceAfterOpeningAndBeforeClosingJsxExpressionBraces?: boolean;
readonly insertSpaceAfterTypeAssertion?: boolean;
readonly insertSpaceBeforeFunctionParenthesis?: boolean;
readonly placeOpenBraceOnNewLineForFunctions?: boolean;
readonly placeOpenBraceOnNewLineForControlBlocks?: boolean;
readonly insertSpaceBeforeTypeAnnotation?: boolean;
readonly indentMultiLineObjectLiteralBeginningOnBlankLine?: boolean;
readonly semicolons?: SemicolonPreference;
}
export function getDefaultFormatCodeSettings(newLineCharacter?: string): FormatCodeSettings {
return {
indentSize: 4,
tabSize: 4,
newLineCharacter: newLineCharacter || "\n",
convertTabsToSpaces: true,
indentStyle: IndentStyle.Smart,
insertSpaceAfterConstructor: false,
insertSpaceAfterCommaDelimiter: true,
insertSpaceAfterSemicolonInForStatements: true,
insertSpaceBeforeAndAfterBinaryOperators: true,
insertSpaceAfterKeywordsInControlFlowStatements: true,
insertSpaceAfterFunctionKeywordForAnonymousFunctions: false,
insertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis: false,
insertSpaceAfterOpeningAndBeforeClosingNonemptyBrackets: false,
insertSpaceAfterOpeningAndBeforeClosingNonemptyBraces: true,
insertSpaceAfterOpeningAndBeforeClosingTemplateStringBraces: false,
insertSpaceAfterOpeningAndBeforeClosingJsxExpressionBraces: false,
insertSpaceBeforeFunctionParenthesis: false,
placeOpenBraceOnNewLineForFunctions: false,
placeOpenBraceOnNewLineForControlBlocks: false,
semicolons: SemicolonPreference.Ignore,
trimTrailingWhitespace: true
};
}
/* @internal */
export const testFormatSettings = getDefaultFormatCodeSettings("\n");
export interface DefinitionInfo extends DocumentSpan {
kind: ScriptElementKind;
name: string;
containerKind: ScriptElementKind;
containerName: string;
unverified?: boolean;
/* @internal */ isLocal?: boolean;
}
export interface DefinitionInfoAndBoundSpan {
definitions?: readonly DefinitionInfo[];
textSpan: TextSpan;
}
export interface ReferencedSymbolDefinitionInfo extends DefinitionInfo {
displayParts: SymbolDisplayPart[];
}
2017-03-27 20:51:13 +02:00
export interface ReferencedSymbol {
definition: ReferencedSymbolDefinitionInfo;
2017-03-27 20:51:13 +02:00
references: ReferenceEntry[];
}
export enum SymbolDisplayPartKind {
aliasName,
className,
enumName,
fieldName,
interfaceName,
keyword,
lineBreak,
numericLiteral,
stringLiteral,
localName,
methodName,
moduleName,
operator,
parameterName,
propertyName,
punctuation,
space,
text,
typeParameterName,
enumMemberName,
functionName,
regularExpressionLiteral,
link,
linkName,
linkText,
}
export interface SymbolDisplayPart {
text: string;
kind: string;
}
export interface JSDocLinkDisplayPart extends SymbolDisplayPart {
target: DocumentSpan;
}
export interface JSDocTagInfo {
name: string;
text?: SymbolDisplayPart[];
}
export interface QuickInfo {
kind: ScriptElementKind;
kindModifiers: string;
textSpan: TextSpan;
Enable '--strictNullChecks' (#22088) * Enable '--strictNullChecks' * Fix API baselines * Make sys.getEnvironmentVariable non-nullable * make properties optional instead of using `| undefined` in thier type * reportDiagnostics should be required * Declare firstAccessor as non-nullable * Make `some` a type guard * Fix `getEnvironmentVariable` definition in tests * Pretend transformFlags are always defined * Fix one more use of sys.getEnvironmentVariable * `requiredResponse` accepts undefined, remove assertions * Mark optional properties as optional instead of using `| undefined` * Mark optional properties as optional instead of using ` | undefined` * Remove unnecessary null assertions * Put the bang on the declaration instead of every use * Make `createMapFromTemplate` require a parameter * Mark `EmitResult.emittedFiles` and `EmitResult.sourceMaps` as optional * Plumb through undefined in emitLsit and EmitExpressionList * `ElementAccessExpression.argumentExpression` can not be `undefined` * Add overloads for `writeTokenText` * Make `shouldWriteSeparatingLineTerminator` argument non-nullable * Make `synthesizedNodeStartsOnNewLine` argument required * `PropertyAssignment.initializer` cannot be undefined * Use one `!` at declaration site instead of on every use site * Capture host in a constant and avoid null assertions * Remove few more unused assertions * Update baselines * Use parameter defaults * Update baselines * Fix lint * Make Symbol#valueDeclaration and Symbol#declarations non-optional to reduce assertions * Make Node#symbol and Type#symbol non-optional to reduce assertions * Make `flags` non-nullable to reduce assertions * Convert some asserts to type guards * Make `isNonLocalAlias` a type guard * Add overload for `getSymbolOfNode` for `Declaration` * Some more `getSymbolOfNode` changes * Push undefined suppression into `typeToTypeNodeHelper` * `NodeBuilderContext.tracker` is never `undefined` * use `Debug.assertDefined` * Remove unnecessary tag * Mark `LiteralType.freshType` and `LiteralTupe.regularType` as required
2018-05-22 23:46:57 +02:00
displayParts?: SymbolDisplayPart[];
documentation?: SymbolDisplayPart[];
tags?: JSDocTagInfo[];
}
2018-09-27 17:56:40 +02:00
export type RenameInfo = RenameInfoSuccess | RenameInfoFailure;
export interface RenameInfoSuccess {
canRename: true;
/**
* File or directory to rename.
* If set, `getEditsForFileRename` should be called instead of `findRenameLocations`.
*/
fileToRename?: string;
displayName: string;
fullDisplayName: string;
kind: ScriptElementKind;
kindModifiers: string;
triggerSpan: TextSpan;
}
2018-09-27 17:56:40 +02:00
export interface RenameInfoFailure {
canRename: false;
localizedErrorMessage: string;
}
export interface RenameInfoOptions {
readonly allowRenameOfImportPath?: boolean;
}
export interface DocCommentTemplateOptions {
readonly generateReturnInDocTemplate?: boolean;
}
export interface SignatureHelpParameter {
name: string;
documentation: SymbolDisplayPart[];
displayParts: SymbolDisplayPart[];
isOptional: boolean;
isRest?: boolean;
}
2019-04-12 02:32:40 +02:00
export interface SelectionRange {
textSpan: TextSpan;
parent?: SelectionRange;
}
/**
* Represents a single signature to show in signature help.
* The id is used for subsequent calls into the language service to ask questions about the
* signature help item in the context of any documents that have been updated. i.e. after
* an edit has happened, while signature help is still active, the host can ask important
* questions like 'what parameter is the user currently contained within?'.
*/
export interface SignatureHelpItem {
isVariadic: boolean;
prefixDisplayParts: SymbolDisplayPart[];
suffixDisplayParts: SymbolDisplayPart[];
separatorDisplayParts: SymbolDisplayPart[];
parameters: SignatureHelpParameter[];
documentation: SymbolDisplayPart[];
tags: JSDocTagInfo[];
}
/**
* Represents a set of signature help items, and the preferred item that should be selected.
*/
export interface SignatureHelpItems {
items: SignatureHelpItem[];
applicableSpan: TextSpan;
selectedItemIndex: number;
argumentIndex: number;
argumentCount: number;
}
export interface CompletionInfo {
/** Not true for all global completions. This will be true if the enclosing scope matches a few syntax kinds. See `isSnippetScope`. */
isGlobalCompletion: boolean;
isMemberCompletion: boolean;
/**
* In the absence of `CompletionEntry["replacementSpan"], the editor may choose whether to use
* this span or its default one. If `CompletionEntry["replacementSpan"]` is defined, that span
* must be used to commit that completion entry.
*/
optionalReplacementSpan?: TextSpan;
2016-09-24 02:37:11 +02:00
/**
* true when the current location also allows for a new identifier
*/
isNewIdentifierLocation: boolean;
Import statement completions (#43149) * WIP * WIP * Get completion details working * Start unifying eager and lazy auto imports * Fix export= * Fix completion details for totally misspelled names * Almost fixed duplication... * Fix remaining completion tests * Refactor to support multiple origins for same symbol * Make import fixes make slightly more sense * Add cache back in * Set insertText based on import kind * Update API baselines * Add semicolons, snippet support, and sourceDisplay * Add some tests * Update baselines * Fix pattern ambient modules appearing in auto imports * Fix tests * Remove commented code * Switch to valueDeclaration for getting module source file * Small optimizations * Cache module specifiers / importableness and export map separately * Fix and test cache invalidation logic * Update API baselines * Add separate user preference for snippet-formatted completions * Require first character to match when resolving module specifiers * Fix AutoImportProvider export map cache invalidation * Really fix auto import provider export map invalidation * Update test added in master * Use logical or assignment Co-authored-by: Daniel Rosenwasser <DanielRosenwasser@users.noreply.github.com> * Simply conditional by reversing Co-authored-by: Daniel Rosenwasser <DanielRosenwasser@users.noreply.github.com> * When file is deleted need to marked correctly in the project as removed file * Simplify hasAddedOrRemovedSymlinks with cherry-picked fix * Ensure replacement range is on one line * Update baselines Co-authored-by: Daniel Rosenwasser <DanielRosenwasser@users.noreply.github.com> Co-authored-by: Sheetal Nandi <shkamat@microsoft.com>
2021-03-26 22:47:07 +01:00
/**
* Indicates to client to continue requesting completions on subsequent keystrokes.
*/
isIncomplete?: true;
entries: CompletionEntry[];
}
export interface CompletionEntryDataAutoImport {
/**
* The name of the property or export in the module's symbol table. Differs from the completion name
* in the case of InternalSymbolName.ExportEquals and InternalSymbolName.Default.
*/
exportName: string;
Import statement completions (#43149) * WIP * WIP * Get completion details working * Start unifying eager and lazy auto imports * Fix export= * Fix completion details for totally misspelled names * Almost fixed duplication... * Fix remaining completion tests * Refactor to support multiple origins for same symbol * Make import fixes make slightly more sense * Add cache back in * Set insertText based on import kind * Update API baselines * Add semicolons, snippet support, and sourceDisplay * Add some tests * Update baselines * Fix pattern ambient modules appearing in auto imports * Fix tests * Remove commented code * Switch to valueDeclaration for getting module source file * Small optimizations * Cache module specifiers / importableness and export map separately * Fix and test cache invalidation logic * Update API baselines * Add separate user preference for snippet-formatted completions * Require first character to match when resolving module specifiers * Fix AutoImportProvider export map cache invalidation * Really fix auto import provider export map invalidation * Update test added in master * Use logical or assignment Co-authored-by: Daniel Rosenwasser <DanielRosenwasser@users.noreply.github.com> * Simply conditional by reversing Co-authored-by: Daniel Rosenwasser <DanielRosenwasser@users.noreply.github.com> * When file is deleted need to marked correctly in the project as removed file * Simplify hasAddedOrRemovedSymlinks with cherry-picked fix * Ensure replacement range is on one line * Update baselines Co-authored-by: Daniel Rosenwasser <DanielRosenwasser@users.noreply.github.com> Co-authored-by: Sheetal Nandi <shkamat@microsoft.com>
2021-03-26 22:47:07 +01:00
moduleSpecifier?: string;
/** The file name declaring the export's module symbol, if it was an external module */
fileName?: string;
/** The module name (with quotes stripped) of the export's module symbol, if it was an ambient module */
ambientModuleName?: string;
/** True if the export was found in the package.json AutoImportProvider */
isPackageJsonImport?: true;
}
export interface CompletionEntryDataUnresolved extends CompletionEntryDataAutoImport {
/** The key in the `ExportMapCache` where the completion entry's `SymbolExportInfo[]` is found */
exportMapKey: string;
}
export interface CompletionEntryDataResolved extends CompletionEntryDataAutoImport {
moduleSpecifier: string;
}
export type CompletionEntryData = CompletionEntryDataUnresolved | CompletionEntryDataResolved;
// see comments in protocol.ts
export interface CompletionEntry {
name: string;
kind: ScriptElementKind;
Enable '--strictNullChecks' (#22088) * Enable '--strictNullChecks' * Fix API baselines * Make sys.getEnvironmentVariable non-nullable * make properties optional instead of using `| undefined` in thier type * reportDiagnostics should be required * Declare firstAccessor as non-nullable * Make `some` a type guard * Fix `getEnvironmentVariable` definition in tests * Pretend transformFlags are always defined * Fix one more use of sys.getEnvironmentVariable * `requiredResponse` accepts undefined, remove assertions * Mark optional properties as optional instead of using `| undefined` * Mark optional properties as optional instead of using ` | undefined` * Remove unnecessary null assertions * Put the bang on the declaration instead of every use * Make `createMapFromTemplate` require a parameter * Mark `EmitResult.emittedFiles` and `EmitResult.sourceMaps` as optional * Plumb through undefined in emitLsit and EmitExpressionList * `ElementAccessExpression.argumentExpression` can not be `undefined` * Add overloads for `writeTokenText` * Make `shouldWriteSeparatingLineTerminator` argument non-nullable * Make `synthesizedNodeStartsOnNewLine` argument required * `PropertyAssignment.initializer` cannot be undefined * Use one `!` at declaration site instead of on every use site * Capture host in a constant and avoid null assertions * Remove few more unused assertions * Update baselines * Use parameter defaults * Update baselines * Fix lint * Make Symbol#valueDeclaration and Symbol#declarations non-optional to reduce assertions * Make Node#symbol and Type#symbol non-optional to reduce assertions * Make `flags` non-nullable to reduce assertions * Convert some asserts to type guards * Make `isNonLocalAlias` a type guard * Add overload for `getSymbolOfNode` for `Declaration` * Some more `getSymbolOfNode` changes * Push undefined suppression into `typeToTypeNodeHelper` * `NodeBuilderContext.tracker` is never `undefined` * use `Debug.assertDefined` * Remove unnecessary tag * Mark `LiteralType.freshType` and `LiteralTupe.regularType` as required
2018-05-22 23:46:57 +02:00
kindModifiers?: string; // see ScriptElementKindModifier, comma separated
sortText: string;
insertText?: string;
Import statement completions (#43149) * WIP * WIP * Get completion details working * Start unifying eager and lazy auto imports * Fix export= * Fix completion details for totally misspelled names * Almost fixed duplication... * Fix remaining completion tests * Refactor to support multiple origins for same symbol * Make import fixes make slightly more sense * Add cache back in * Set insertText based on import kind * Update API baselines * Add semicolons, snippet support, and sourceDisplay * Add some tests * Update baselines * Fix pattern ambient modules appearing in auto imports * Fix tests * Remove commented code * Switch to valueDeclaration for getting module source file * Small optimizations * Cache module specifiers / importableness and export map separately * Fix and test cache invalidation logic * Update API baselines * Add separate user preference for snippet-formatted completions * Require first character to match when resolving module specifiers * Fix AutoImportProvider export map cache invalidation * Really fix auto import provider export map invalidation * Update test added in master * Use logical or assignment Co-authored-by: Daniel Rosenwasser <DanielRosenwasser@users.noreply.github.com> * Simply conditional by reversing Co-authored-by: Daniel Rosenwasser <DanielRosenwasser@users.noreply.github.com> * When file is deleted need to marked correctly in the project as removed file * Simplify hasAddedOrRemovedSymlinks with cherry-picked fix * Ensure replacement range is on one line * Update baselines Co-authored-by: Daniel Rosenwasser <DanielRosenwasser@users.noreply.github.com> Co-authored-by: Sheetal Nandi <shkamat@microsoft.com>
2021-03-26 22:47:07 +01:00
isSnippet?: true;
/**
* An optional span that indicates the text to be replaced by this completion item.
* If present, this span should be used instead of the default one.
* It will be set if the required span differs from the one generated by the default replacement behavior.
2017-04-03 18:32:39 +02:00
*/
replacementSpan?: TextSpan;
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
hasAction?: true;
source?: string;
Import statement completions (#43149) * WIP * WIP * Get completion details working * Start unifying eager and lazy auto imports * Fix export= * Fix completion details for totally misspelled names * Almost fixed duplication... * Fix remaining completion tests * Refactor to support multiple origins for same symbol * Make import fixes make slightly more sense * Add cache back in * Set insertText based on import kind * Update API baselines * Add semicolons, snippet support, and sourceDisplay * Add some tests * Update baselines * Fix pattern ambient modules appearing in auto imports * Fix tests * Remove commented code * Switch to valueDeclaration for getting module source file * Small optimizations * Cache module specifiers / importableness and export map separately * Fix and test cache invalidation logic * Update API baselines * Add separate user preference for snippet-formatted completions * Require first character to match when resolving module specifiers * Fix AutoImportProvider export map cache invalidation * Really fix auto import provider export map invalidation * Update test added in master * Use logical or assignment Co-authored-by: Daniel Rosenwasser <DanielRosenwasser@users.noreply.github.com> * Simply conditional by reversing Co-authored-by: Daniel Rosenwasser <DanielRosenwasser@users.noreply.github.com> * When file is deleted need to marked correctly in the project as removed file * Simplify hasAddedOrRemovedSymlinks with cherry-picked fix * Ensure replacement range is on one line * Update baselines Co-authored-by: Daniel Rosenwasser <DanielRosenwasser@users.noreply.github.com> Co-authored-by: Sheetal Nandi <shkamat@microsoft.com>
2021-03-26 22:47:07 +01:00
sourceDisplay?: SymbolDisplayPart[];
isRecommended?: true;
2020-01-07 21:57:11 +01:00
isFromUncheckedFile?: true;
Expand auto-import to all package.json dependencies (#38923) * Start experiment * Add logging * Go back to a single program * Fix forEachExternalModuleToImportFrom * Move auxiliary program to language service * Add logging * Don’t use resolution cache * Fix(?) containingProjects for ScriptInfo in auxiliary program * Fix ScriptInfo project inclusion * Add test for default project of auto-importable ScriptInfo * Add fourslash server test * Don’t create auto import provider inside node_modules * Add monorepo-like test * WIP * Naively ensure autoImportProvider is up to date after package.json change * Start limiting when auto update provider gets updated * Respond to changes in node_modules * Don’t create auto-import provider until a file is open that would use it e.g., don’t create them during cross-project find-all-refs * Clean up naming, @internal marking, and fix empty project creation bug * Drop devDependencies, include peerDependencies * Add additional compiler options * Fix interaction with importSuggestionsCache * Move option to UserPreferences, allow inclusion of devDependencies * Don’t filter out peerDependencies * Watch unparseable package.jsons * But don’t filter packages out due to an invalid package.json * Update test * Don’t use autoImportProvider in codefixes where it can never be used (or any refactors) * Add CompletionEntry property for telemetry * Add assertion for isPackageJsonImport to fourslash * Fix missing pushSymbol argument * Add isPackageJsonImport to tests and API baselines * Fix unit test * Host auto import provider in new Project kind * Fix InferredProject attaching on AutoImportProvider-included files, load eagerly * Update Public APIs * Simplify PackageJsonCache host * Remove unneeded markAsDirty * Defer project finished event until after AutoImportProvider is created * Make AutoImportProviderProject always report isOrphan = true * Close and remove AutoImportProviderProject when host project closes * Don’t set pendingEnsureProjectForOpenFiles * Use hasAddedOrRemovedFiles instead of hasNewProgram * Use host-wide watchOptions for package.json watching * Add to `printProjects` * Clean up * Get autoImportProvider directly from LanguageServiceHost * Clean up * Clean up * Close auto import provider on disableLanguageService * Move AutoImportProvider preload to project updateGraph * Clear auto import suggestion cache when provider program changes * Fix tests * Revert yet-unneeded change * Use projectService host for module resolution host * Don’t re-resolve type directives if nothing has changed * Update src/server/project.ts Co-authored-by: Sheetal Nandi <shkamat@microsoft.com> * Use ts.emptyArray Co-authored-by: Sheetal Nandi <shkamat@microsoft.com>
2020-06-23 01:34:27 +02:00
isPackageJsonImport?: true;
isImportStatementCompletion?: true;
/**
* A property to be sent back to TS Server in the CompletionDetailsRequest, along with `name`,
* that allows TS Server to look up the symbol represented by the completion item, disambiguating
* items with the same name. Currently only defined for auto-import completions, but the type is
* `unknown` in the protocol, so it can be changed as needed to support other kinds of completions.
* The presence of this property should generally not be used to assume that this completion entry
* is an auto-import.
*/
data?: CompletionEntryData;
}
export interface CompletionEntryDetails {
name: string;
kind: ScriptElementKind;
kindModifiers: string; // see ScriptElementKindModifier, comma separated
displayParts: SymbolDisplayPart[];
Enable '--strictNullChecks' (#22088) * Enable '--strictNullChecks' * Fix API baselines * Make sys.getEnvironmentVariable non-nullable * make properties optional instead of using `| undefined` in thier type * reportDiagnostics should be required * Declare firstAccessor as non-nullable * Make `some` a type guard * Fix `getEnvironmentVariable` definition in tests * Pretend transformFlags are always defined * Fix one more use of sys.getEnvironmentVariable * `requiredResponse` accepts undefined, remove assertions * Mark optional properties as optional instead of using `| undefined` * Mark optional properties as optional instead of using ` | undefined` * Remove unnecessary null assertions * Put the bang on the declaration instead of every use * Make `createMapFromTemplate` require a parameter * Mark `EmitResult.emittedFiles` and `EmitResult.sourceMaps` as optional * Plumb through undefined in emitLsit and EmitExpressionList * `ElementAccessExpression.argumentExpression` can not be `undefined` * Add overloads for `writeTokenText` * Make `shouldWriteSeparatingLineTerminator` argument non-nullable * Make `synthesizedNodeStartsOnNewLine` argument required * `PropertyAssignment.initializer` cannot be undefined * Use one `!` at declaration site instead of on every use site * Capture host in a constant and avoid null assertions * Remove few more unused assertions * Update baselines * Use parameter defaults * Update baselines * Fix lint * Make Symbol#valueDeclaration and Symbol#declarations non-optional to reduce assertions * Make Node#symbol and Type#symbol non-optional to reduce assertions * Make `flags` non-nullable to reduce assertions * Convert some asserts to type guards * Make `isNonLocalAlias` a type guard * Add overload for `getSymbolOfNode` for `Declaration` * Some more `getSymbolOfNode` changes * Push undefined suppression into `typeToTypeNodeHelper` * `NodeBuilderContext.tracker` is never `undefined` * use `Debug.assertDefined` * Remove unnecessary tag * Mark `LiteralType.freshType` and `LiteralTupe.regularType` as required
2018-05-22 23:46:57 +02:00
documentation?: SymbolDisplayPart[];
tags?: JSDocTagInfo[];
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
codeActions?: CodeAction[];
Import statement completions (#43149) * WIP * WIP * Get completion details working * Start unifying eager and lazy auto imports * Fix export= * Fix completion details for totally misspelled names * Almost fixed duplication... * Fix remaining completion tests * Refactor to support multiple origins for same symbol * Make import fixes make slightly more sense * Add cache back in * Set insertText based on import kind * Update API baselines * Add semicolons, snippet support, and sourceDisplay * Add some tests * Update baselines * Fix pattern ambient modules appearing in auto imports * Fix tests * Remove commented code * Switch to valueDeclaration for getting module source file * Small optimizations * Cache module specifiers / importableness and export map separately * Fix and test cache invalidation logic * Update API baselines * Add separate user preference for snippet-formatted completions * Require first character to match when resolving module specifiers * Fix AutoImportProvider export map cache invalidation * Really fix auto import provider export map invalidation * Update test added in master * Use logical or assignment Co-authored-by: Daniel Rosenwasser <DanielRosenwasser@users.noreply.github.com> * Simply conditional by reversing Co-authored-by: Daniel Rosenwasser <DanielRosenwasser@users.noreply.github.com> * When file is deleted need to marked correctly in the project as removed file * Simplify hasAddedOrRemovedSymlinks with cherry-picked fix * Ensure replacement range is on one line * Update baselines Co-authored-by: Daniel Rosenwasser <DanielRosenwasser@users.noreply.github.com> Co-authored-by: Sheetal Nandi <shkamat@microsoft.com>
2021-03-26 22:47:07 +01:00
/** @deprecated Use `sourceDisplay` instead. */
source?: SymbolDisplayPart[];
Import statement completions (#43149) * WIP * WIP * Get completion details working * Start unifying eager and lazy auto imports * Fix export= * Fix completion details for totally misspelled names * Almost fixed duplication... * Fix remaining completion tests * Refactor to support multiple origins for same symbol * Make import fixes make slightly more sense * Add cache back in * Set insertText based on import kind * Update API baselines * Add semicolons, snippet support, and sourceDisplay * Add some tests * Update baselines * Fix pattern ambient modules appearing in auto imports * Fix tests * Remove commented code * Switch to valueDeclaration for getting module source file * Small optimizations * Cache module specifiers / importableness and export map separately * Fix and test cache invalidation logic * Update API baselines * Add separate user preference for snippet-formatted completions * Require first character to match when resolving module specifiers * Fix AutoImportProvider export map cache invalidation * Really fix auto import provider export map invalidation * Update test added in master * Use logical or assignment Co-authored-by: Daniel Rosenwasser <DanielRosenwasser@users.noreply.github.com> * Simply conditional by reversing Co-authored-by: Daniel Rosenwasser <DanielRosenwasser@users.noreply.github.com> * When file is deleted need to marked correctly in the project as removed file * Simplify hasAddedOrRemovedSymlinks with cherry-picked fix * Ensure replacement range is on one line * Update baselines Co-authored-by: Daniel Rosenwasser <DanielRosenwasser@users.noreply.github.com> Co-authored-by: Sheetal Nandi <shkamat@microsoft.com>
2021-03-26 22:47:07 +01:00
sourceDisplay?: SymbolDisplayPart[];
}
export interface OutliningSpan {
/** The span of the document to actually collapse. */
textSpan: TextSpan;
/** The span of the document to display when the user hovers over the collapsed span. */
hintSpan: TextSpan;
/** The text to display in the editor for the collapsed region. */
bannerText: string;
/**
2017-04-03 18:32:39 +02:00
* Whether or not this region should be automatically collapsed when
* the 'Collapse to Definitions' command is invoked.
*/
autoCollapse: boolean;
/**
* Classification of the contents of the span
*/
kind: OutliningSpanKind;
}
export const enum OutliningSpanKind {
2018-05-05 21:38:59 +02:00
/** Single or multi-line comments */
Comment = "comment",
2018-05-05 21:38:59 +02:00
/** Sections marked by '// #region' and '// #endregion' comments */
Region = "region",
2018-05-05 21:38:59 +02:00
/** Declarations and expressions */
Code = "code",
2018-05-05 21:38:59 +02:00
/** Contiguous blocks of import declarations */
2018-05-05 21:02:29 +02:00
Imports = "imports"
}
export const enum OutputFileType {
JavaScript,
SourceMap,
Declaration
}
export const enum EndOfLineState {
None,
InMultiLineCommentTrivia,
InSingleQuoteStringLiteral,
InDoubleQuoteStringLiteral,
InTemplateHeadOrNoSubstitutionTemplate,
InTemplateMiddleOrTail,
InTemplateSubstitutionPosition,
}
export enum TokenClass {
Punctuation,
Keyword,
Operator,
Comment,
Whitespace,
Identifier,
NumberLiteral,
2018-10-31 00:56:05 +01:00
BigIntLiteral,
StringLiteral,
RegExpLiteral,
}
export interface ClassificationResult {
finalLexState: EndOfLineState;
entries: ClassificationInfo[];
}
export interface ClassificationInfo {
length: number;
classification: TokenClass;
}
export interface Classifier {
/**
* Gives lexical classifications of tokens on a line without any syntactic context.
* For instance, a token consisting of the text 'string' can be either an identifier
* named 'string' or the keyword 'string', however, because this classifier is not aware,
* it relies on certain heuristics to give acceptable results. For classifications where
* speed trumps accuracy, this function is preferable; however, for true accuracy, the
* syntactic classifier is ideal. In fact, in certain editing scenarios, combining the
* lexical, syntactic, and semantic classifiers may issue the best user experience.
*
* @param text The text of a line to classify.
* @param lexState The state of the lexical classifier at the end of the previous line.
* @param syntacticClassifierAbsent Whether the client is *not* using a syntactic classifier.
* If there is no syntactic classifier (syntacticClassifierAbsent=true),
* certain heuristics may be used in its place; however, if there is a
* syntactic classifier (syntacticClassifierAbsent=false), certain
* classifications which may be incorrectly categorized will be given
* back as Identifiers in order to allow the syntactic classifier to
* subsume the classification.
* @deprecated Use getLexicalClassifications instead.
*/
getClassificationsForLine(text: string, lexState: EndOfLineState, syntacticClassifierAbsent: boolean): ClassificationResult;
getEncodedLexicalClassifications(text: string, endOfLineState: EndOfLineState, syntacticClassifierAbsent: boolean): Classifications;
}
export const enum ScriptElementKind {
unknown = "",
warning = "warning",
/** predefined type (void) or keyword (class) */
keyword = "keyword",
/** top level script node */
scriptElement = "script",
/** module foo {} */
moduleElement = "module",
/** class X {} */
classElement = "class",
/** var x = class X {} */
localClassElement = "local class",
/** interface Y {} */
interfaceElement = "interface",
/** type T = ... */
typeElement = "type",
/** enum E */
enumElement = "enum",
enumMemberElement = "enum member",
/**
* Inside module and script only
* const v = ..
*/
variableElement = "var",
/** Inside function */
localVariableElement = "local var",
/**
* Inside module and script only
* function f() { }
*/
functionElement = "function",
/** Inside function */
localFunctionElement = "local function",
/** class X { [public|private]* foo() {} } */
memberFunctionElement = "method",
/** class X { [public|private]* [get|set] foo:number; } */
memberGetAccessorElement = "getter",
memberSetAccessorElement = "setter",
/**
* class X { [public|private]* foo:number; }
* interface Y { foo:number; }
*/
memberVariableElement = "property",
/**
* class X { constructor() { } }
* class X { static { } }
*/
constructorImplementationElement = "constructor",
/** interface Y { ():number; } */
callSignatureElement = "call",
/** interface Y { []:number; } */
indexSignatureElement = "index",
/** interface Y { new():Y; } */
constructSignatureElement = "construct",
/** function foo(*Y*: string) */
parameterElement = "parameter",
typeParameterElement = "type parameter",
primitiveType = "primitive type",
label = "label",
alias = "alias",
constElement = "const",
letElement = "let",
directory = "directory",
externalModuleName = "external module name",
/**
* <JsxTagName attribute1 attribute2={0} />
2017-04-03 18:32:39 +02:00
*/
jsxAttribute = "JSX attribute",
/** String literal */
string = "string",
/** Jsdoc @link: in `{@link C link text}`, the before and after text "{@link " and "}" */
link = "link",
/** Jsdoc @link: in `{@link C link text}`, the entity name "C" */
linkName = "link name",
/** Jsdoc @link: in `{@link C link text}`, the link text "link text" */
linkText = "link text",
}
export const enum ScriptElementKindModifier {
none = "",
publicMemberModifier = "public",
privateMemberModifier = "private",
protectedMemberModifier = "protected",
exportedModifier = "export",
ambientModifier = "declare",
staticModifier = "static",
abstractModifier = "abstract",
optionalModifier = "optional",
deprecatedModifier = "deprecated",
dtsModifier = ".d.ts",
tsModifier = ".ts",
tsxModifier = ".tsx",
jsModifier = ".js",
jsxModifier = ".jsx",
jsonModifier = ".json",
dmtsModifier = ".d.mts",
mtsModifier = ".mts",
mjsModifier = ".mjs",
dctsModifier = ".d.cts",
ctsModifier = ".cts",
cjsModifier = ".cjs",
}
export const enum ClassificationTypeNames {
comment = "comment",
identifier = "identifier",
keyword = "keyword",
numericLiteral = "number",
2018-10-31 00:56:05 +01:00
bigintLiteral = "bigint",
operator = "operator",
stringLiteral = "string",
whiteSpace = "whitespace",
text = "text",
punctuation = "punctuation",
className = "class name",
enumName = "enum name",
interfaceName = "interface name",
moduleName = "module name",
typeParameterName = "type parameter name",
typeAliasName = "type alias name",
parameterName = "parameter name",
docCommentTagName = "doc comment tag name",
jsxOpenTagName = "jsx open tag name",
jsxCloseTagName = "jsx close tag name",
jsxSelfClosingTagName = "jsx self closing tag name",
jsxAttribute = "jsx attribute",
jsxText = "jsx text",
jsxAttributeStringLiteralValue = "jsx attribute string literal value",
}
export const enum ClassificationType {
comment = 1,
identifier = 2,
keyword = 3,
numericLiteral = 4,
operator = 5,
stringLiteral = 6,
regularExpressionLiteral = 7,
whiteSpace = 8,
text = 9,
punctuation = 10,
className = 11,
enumName = 12,
interfaceName = 13,
moduleName = 14,
typeParameterName = 15,
typeAliasName = 16,
parameterName = 17,
docCommentTagName = 18,
jsxOpenTagName = 19,
jsxCloseTagName = 20,
jsxSelfClosingTagName = 21,
jsxAttribute = 22,
jsxText = 23,
jsxAttributeStringLiteralValue = 24,
2018-10-31 00:56:05 +01:00
bigintLiteral = 25,
}
/** @internal */
export interface CodeFixRegistration {
errorCodes: readonly number[];
getCodeActions(context: CodeFixContext): CodeFixAction[] | undefined;
fixIds?: readonly string[];
getAllCodeActions?(context: CodeFixAllContext): CombinedCodeActions;
}
/** @internal */
export interface CodeFixContextBase extends textChanges.TextChangesContext {
sourceFile: SourceFile;
program: Program;
cancellationToken: CancellationToken;
preferences: UserPreferences;
}
/** @internal */
export interface CodeFixAllContext extends CodeFixContextBase {
fixId: {};
}
/** @internal */
export interface CodeFixContext extends CodeFixContextBase {
errorCode: number;
span: TextSpan;
}
/** @internal */
export interface Refactor {
/** List of action kinds a refactor can provide.
* Used to skip unnecessary calculation when specific refactors are requested. */
kinds?: string[];
/** Compute the associated code actions */
getEditsForAction(context: RefactorContext, actionName: string): RefactorEditInfo | undefined;
/** Compute (quickly) which actions are available here */
getAvailableActions(context: RefactorContext): readonly ApplicableRefactorInfo[];
}
/** @internal */
export interface RefactorContext extends textChanges.TextChangesContext {
file: SourceFile;
startPosition: number;
endPosition?: number;
program: Program;
cancellationToken?: CancellationToken;
preferences: UserPreferences;
2020-04-14 22:17:19 +02:00
triggerReason?: RefactorTriggerReason;
kind?: string;
}
Add inlay hints support (#42089) * Add signature arguments label support * Support rest parameters and destruction * make lint * Fix tuple rest parameters * Adjust name styles * Rename to inline hints * Partition inline hints * Adjust range pred * Add function expression like hints * Support configure inline hints * Display hints in single line * Add test suits and tests * Add range tests * Support more hints * Add more options * Fix logical * Add more cases * Support call chains * Rename options * Match lastest protocol * Update protocol changes * Support context value and hover message * Revert "Support context value and hover message" This reverts commit 37a70896337ddd6dd5360d20e7001ed2338a2595. * Revert "Update protocol changes" This reverts commit e5ca31bc30362144c52c1c2512abc553f0c6b869. * Add hover message * Accept baseline * Update src/services/inlineHints.ts Co-authored-by: Daniel Rosenwasser <DanielRosenwasser@users.noreply.github.com> * Update src/services/inlineHints.ts Co-authored-by: Daniel Rosenwasser <DanielRosenwasser@users.noreply.github.com> * Cache across the program * Fix possible undefined * Update protocol changes * Fix missing property * Make lint happy * Avoid call chain hints * I'm bad * Add whitespace before type * Add more tests * Should care about jsdoc * Support complex rest parameter * Avoid module symbol hints * Care about leading comments * Fix CR issues * Avoid changes * Simplify comments contains * Fix CR issues * Accept baseline * Check parameter name before create regex * Rename option * Avoid makers * Skip parens for argument * Fix CR issues * Fix enums * Accept baseline Co-authored-by: Daniel Rosenwasser <DanielRosenwasser@users.noreply.github.com>
2021-06-25 08:06:34 +02:00
export interface InlayHintsContext {
file: SourceFile;
program: Program;
cancellationToken: CancellationToken;
host: LanguageServiceHost;
span: TextSpan;
preferences: InlayHintsOptions;
}
}