javascript-typescript-langserver
Version:
Implementation of the Language Server Protocol for JavaScript and TypeScript
91 lines (90 loc) • 3.26 kB
TypeScript
/// <reference types="node" />
import { EventEmitter } from 'events';
import { Span } from 'opentracing';
import { Observable } from 'rxjs';
import { Disposable } from './disposable';
import { FileSystemUpdater } from './fs';
import { Logger } from './logging';
import { InMemoryFileSystem } from './memfs';
/**
* Schema of a package.json file
*/
export interface PackageJson {
name?: string;
version?: string;
typings?: string;
repository?: string | {
type: string;
url: string;
};
dependencies?: {
[packageName: string]: string;
};
devDependencies?: {
[packageName: string]: string;
};
peerDependencies?: {
[packageName: string]: string;
};
optionalDependencies?: {
[packageName: string]: string;
};
}
export declare const DEPENDENCY_KEYS: ReadonlyArray<'dependencies' | 'devDependencies' | 'peerDependencies' | 'optionalDependencies'>;
/**
* Returns the name of a package that a file is contained in
*/
export declare function extractNodeModulesPackageName(uri: string): string | undefined;
/**
* Returns the name of a package that a file in DefinitelyTyped defines.
* E.g. `file:///foo/types/node/index.d.ts` -> `@types/node`
*/
export declare function extractDefinitelyTypedPackageName(uri: string): string | undefined;
export declare class PackageManager extends EventEmitter implements Disposable {
private updater;
private inMemoryFileSystem;
private logger;
/**
* Map of package.json URIs _defined_ in the workspace to optional content.
* Does not include package.jsons of dependencies.
* Updated as new package.jsons are discovered.
*/
private packages;
/**
* The URI of the root package.json, if any.
* Updated as new package.jsons are discovered.
*/
rootPackageJsonUri: string | undefined;
/**
* Subscriptions to unsubscribe from on object disposal
*/
private subscriptions;
constructor(updater: FileSystemUpdater, inMemoryFileSystem: InMemoryFileSystem, logger?: Logger);
dispose(): void;
/** Emitted when a new package.json was found and parsed */
on(event: 'parsed', listener: (uri: string, packageJson: PackageJson) => void): this;
/**
* Returns an Iterable for all package.jsons in the workspace
*/
packageJsonUris(): IterableIterator<string>;
/**
* Gets the content of the closest package.json known to to the DependencyManager in the ancestors of a URI
*
* @return Observable that emits a single PackageJson or never
*/
getClosestPackageJson(uri: string, span?: Span): Observable<PackageJson>;
/**
* Returns the parsed package.json of the passed URI
*
* @param uri URI of the package.json
* @return Observable that emits a single PackageJson or never
*/
getPackageJson(uri: string, childOf?: Span): Observable<PackageJson>;
/**
* Walks the parent directories of a given URI to find the first package.json that is known to the InMemoryFileSystem
*
* @param uri URI of a file or directory in the workspace
* @return The found package.json or undefined if none found
*/
getClosestPackageJsonUri(uri: string): string | undefined;
}