Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LanguageServiceHost.getDefaultLibFileName is confusing #35318

Closed
SimonSiefke opened this issue Nov 24, 2019 · 2 comments
Closed

LanguageServiceHost.getDefaultLibFileName is confusing #35318

SimonSiefke opened this issue Nov 24, 2019 · 2 comments
Labels
Unactionable There isn't something we can do with this issue

Comments

@SimonSiefke
Copy link

TypeScript Version: 3.7.2

Search Terms:
LanguageServiceHost, getDefaultLibFileName

Code

import * as ts from 'typescript';

let compilerOptions: ts.CompilerOptions = {
  allowNonTsExtensions: true,
  target: ts.ScriptTarget.Latest,
  module: ts.ModuleKind.ESNext,
  moduleResolution: ts.ModuleResolutionKind.NodeJs,
  allowJs: true
};

const serviceHost: ts.LanguageServiceHost = {
  getScriptFileNames: () => [],
  getScriptVersion: () => '0',
  getScriptSnapshot: path => ts.ScriptSnapshot.fromString(ts.sys.readFile(path)),
  getCurrentDirectory: () => '',
  getCompilationSettings: () => compilerOptions,
  getDefaultLibFileName: ts.getDefaultLibFileName, // this doesn't work
  fileExists: ts.sys.fileExists,
  readFile: ts.sys.readFile,
  readDirectory: ts.sys.readDirectory
};

Expected behavior:
I can pass ts.getDefaultLibFileName for the property getDefaultLibFileName of serviceHost.

Actual behavior:
I have to pass ts.getDefaultLibFilePath for the property getDefaultLibFileName.
When I pass ts.getDefaultLibFileName, getScriptSnapshot only has the fileName (e.g. lib.esnext.full.d.ts) as an argument instead of the full path (e.g. /home/simon/folder/node_modules/typescript/lib/lib.esnext.full.d.ts) and when getScriptSnapshot is called, it fails to read the file.

Maybe the getDefaultLibFileName property could be replaced with a getDefaultLibFilePath property, currently it is a bit confusing :/

Wiki Link: https://github.com/Microsoft/TypeScript/wiki/Using-the-Compiler-API#incremental-build-support-using-the-language-services

@fatcerberus
Copy link

I agree, that is very confusing.

@RyanCavanaugh RyanCavanaugh added the Unactionable There isn't something we can do with this issue label Dec 10, 2019
@RyanCavanaugh
Copy link
Member

This isn't worth taking a breaking change over.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Unactionable There isn't something we can do with this issue
Projects
None yet
Development

No branches or pull requests

3 participants