Skip to content

Commit b0acdc3

Browse files
committed
Adds some docs to the LSP dts
1 parent 7726464 commit b0acdc3

File tree

2 files changed

+83
-11
lines changed

2 files changed

+83
-11
lines changed

src/services/services.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1452,6 +1452,12 @@ namespace ts {
14521452
return computeSuggestionDiagnostics(getValidSourceFile(fileName), program, cancellationToken);
14531453
}
14541454

1455+
// @ts-ignore - 'getProgramDiagnostics' is declared but its value is never read - this is because it is a dupe of getCompilerOptionsDiagnostics
1456+
// so that the external interface makes more sense.
1457+
function getProgramDiagnostics() {
1458+
return getCompilerOptionsDiagnostics();
1459+
}
1460+
14551461
function getCompilerOptionsDiagnostics() {
14561462
synchronizeHostData();
14571463
return [...program.getOptionsDiagnostics(cancellationToken), ...program.getGlobalDiagnostics(cancellationToken)];
@@ -2178,6 +2184,7 @@ namespace ts {
21782184
getSyntacticDiagnostics,
21792185
getSemanticDiagnostics,
21802186
getSuggestionDiagnostics,
2187+
getProgramDiagnostics: getCompilerOptionsDiagnostics,
21812188
getCompilerOptionsDiagnostics,
21822189
getSyntacticClassifications,
21832190
getSemanticClassifications,

src/services/types.ts

Lines changed: 76 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -289,43 +289,108 @@ namespace ts {
289289
// with a language service host instance
290290
//
291291
export interface LanguageService {
292+
/** This is used as a part of restarting the language server */
292293
cleanupSemanticCache(): void;
293294

295+
/**
296+
* Gets warnings or errors indicating invalid syntax in a given file.
297+
* These diagnostics are inexpensive to compute and don't require knowledge of other
298+
* files. Note that a non-empty result increases the likelihood of false positives
299+
* from getSemanticDiagnostics.
300+
*
301+
* While these represent the majority of syntax-related diagnostics, there are diagnostics
302+
* which require the type-system, and those will be available via getSemanticDiagnostics.
303+
*
304+
* To contrast with English, this cdeo has erorrs." is not syntactically correct because
305+
* it has typoes, even though you can squint to understand.
306+
*
307+
* @param fileName A path to the file you want semantic diagnostics for
308+
*/
294309
getSyntacticDiagnostics(fileName: string): DiagnosticWithLocation[];
295-
/** The first time this is called, it will return global diagnostics (no location). */
296-
getSemanticDiagnostics(fileName: string): Diagnostic[];
297-
getSuggestionDiagnostics(fileName: string): DiagnosticWithLocation[];
298310

299-
// TODO: Rename this to getProgramDiagnostics to better indicate that these are any
300-
// diagnostics present for the program level, and not just 'options' diagnostics.
301-
getCompilerOptionsDiagnostics(): Diagnostic[];
311+
/**
312+
* Gets warnings or errors indicating type system issues in a given file.
313+
* Requesting semantic diagnostics may start-up the type system, and
314+
* run deferred work, so the first time you make this call it may take longer than
315+
* subsequent calls.
316+
*
317+
* Unlike the other get*Diagnostics functions, these diagnostics can potentially not
318+
* include a reference to a source file. Specifically, the first time this is called,
319+
* it will return global diagnostics with no associated location.
320+
*
321+
* To contrast the differences between semantic and syntactic diagnostics, consider the
322+
* sentence: "The sun is green." is syntactically correct; those are all real words
323+
* in english. However, it is semantically invalid, because it is not true.
324+
*
325+
* @param fileName A path to the file you want semantic diagnostics for
326+
*/
327+
getSemanticDiagnostics(fileName: string): Diagnostic[];
302328

303329
/**
304-
* @deprecated Use getEncodedSyntacticClassifications instead.
330+
* Get suggestion diagnostics for a specific files. These suggestions tend
331+
* to be proactive codefixes and refactors, as opposed to issues which require
332+
* fixing in order for the to be correct.
333+
*
334+
* @param fileName A path to the file you want semantic diagnostics for
305335
*/
306-
getSyntacticClassifications(fileName: string, span: TextSpan): ClassifiedSpan[];
336+
getSuggestionDiagnostics(fileName: string): DiagnosticWithLocation[];
307337

308338
/**
309-
* @deprecated Use getEncodedSemanticClassifications instead.
339+
* Gets diagnostics related the current program, these tend to be about the compiler
340+
* options for a project.
310341
*/
342+
getProgramDiagnostics(): Diagnostic[];
343+
344+
/** @deprecated Use getProgramDiagnostics instead. */
345+
getCompilerOptionsDiagnostics(): Diagnostic[];
346+
347+
/** @deprecated Use getEncodedSyntacticClassifications instead. */
348+
getSyntacticClassifications(fileName: string, span: TextSpan): ClassifiedSpan[];
349+
350+
/** @deprecated Use getEncodedSemanticClassifications instead. */
311351
getSemanticClassifications(fileName: string, span: TextSpan): ClassifiedSpan[];
312352

313353
// Encoded as triples of [start, length, ClassificationType].
314354
getEncodedSyntacticClassifications(fileName: string, span: TextSpan): Classifications;
315355
getEncodedSemanticClassifications(fileName: string, span: TextSpan): Classifications;
316356

357+
/**
358+
* Get the completion entries at a particular cursor
359+
*
360+
* @param fileName The path to the file
361+
* @param position A zero based index of the character where you want the entries
362+
* @param options An object describing how the completions were triggered, can be undefined for backwards compatibility
363+
*/
317364
getCompletionsAtPosition(fileName: string, position: number, options: GetCompletionsAtPositionOptions | undefined): WithMetadata<CompletionInfo> | undefined;
318-
// "options" and "source" are optional only for backwards-compatibility
365+
366+
/**
367+
* Gets the extended details for a completion entry
368+
*
369+
* @param fileName The path to the file
370+
* @param position A zero based index of the character where you want the entries
371+
* @param entryName The name from an existing completion which came from `getCompletionsAtPosition`
372+
* @param formatOptions How should code samples in the completions be formatted, can be undefined for backwards compatibility
373+
* @param source Source code for the current file, can be undefined for backwards compatibility
374+
* @param preferences User settings, can be undefined for backwards compatibility
375+
*/
319376
getCompletionEntryDetails(
320377
fileName: string,
321378
position: number,
322-
name: string,
379+
entryName: string,
323380
formatOptions: FormatCodeOptions | FormatCodeSettings | undefined,
324381
source: string | undefined,
325382
preferences: UserPreferences | undefined,
326383
): CompletionEntryDetails | undefined;
384+
327385
getCompletionEntrySymbol(fileName: string, position: number, name: string, source: string | undefined): Symbol | undefined;
328386

387+
/**
388+
* Gets semantic information about the identifier at a particular position in a
389+
* file. Quick info is what you typically see when you hover in an editor.
390+
*
391+
* @param fileName The path to the file
392+
* @param position a zero based index of the character where you want the quick info
393+
*/
329394
getQuickInfoAtPosition(fileName: string, position: number): QuickInfo | undefined;
330395

331396
getNameOrDottedNameSpan(fileName: string, startPos: number, endPos: number): TextSpan | undefined;

0 commit comments

Comments
 (0)