mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-29 16:29:19 -05:00
drop unused code
This commit is contained in:
@@ -16,6 +16,25 @@ namespace ts.server {
|
||||
}
|
||||
|
||||
const lineCollectionCapacity = 4;
|
||||
function getDefaultFormatCodeOptions(host: ServerHost): ts.FormatCodeOptions {
|
||||
return ts.clone(<ts.FormatCodeOptions>{
|
||||
IndentSize: 4,
|
||||
TabSize: 4,
|
||||
NewLineCharacter: host.newLine || "\n",
|
||||
ConvertTabsToSpaces: true,
|
||||
IndentStyle: ts.IndentStyle.Smart,
|
||||
InsertSpaceAfterCommaDelimiter: true,
|
||||
InsertSpaceAfterSemicolonInForStatements: true,
|
||||
InsertSpaceBeforeAndAfterBinaryOperators: true,
|
||||
InsertSpaceAfterKeywordsInControlFlowStatements: true,
|
||||
InsertSpaceAfterFunctionKeywordForAnonymousFunctions: false,
|
||||
InsertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis: false,
|
||||
InsertSpaceAfterOpeningAndBeforeClosingNonemptyBrackets: false,
|
||||
InsertSpaceAfterOpeningAndBeforeClosingTemplateStringBraces: false,
|
||||
PlaceOpenBraceOnNewLineForFunctions: false,
|
||||
PlaceOpenBraceOnNewLineForControlBlocks: false,
|
||||
});
|
||||
}
|
||||
|
||||
function mergeFormatOptions(formatCodeOptions: FormatCodeOptions, formatOptions: protocol.FormatOptions): void {
|
||||
const hasOwnProperty = Object.prototype.hasOwnProperty;
|
||||
@@ -32,13 +51,14 @@ namespace ts.server {
|
||||
children: ScriptInfo[] = []; // files referenced by this file
|
||||
defaultProject: Project; // project to use by default for file
|
||||
fileWatcher: FileWatcher;
|
||||
formatCodeOptions = ts.clone(CompilerService.getDefaultFormatCodeOptions(this.host));
|
||||
formatCodeOptions: ts.FormatCodeOptions;
|
||||
path: Path;
|
||||
scriptKind: ScriptKind;
|
||||
|
||||
constructor(private host: ServerHost, public fileName: string, public content: string, public isOpen = false) {
|
||||
this.path = toPath(fileName, host.getCurrentDirectory(), createGetCanonicalFileName(host.useCaseSensitiveFileNames));
|
||||
this.svc = ScriptVersionCache.fromString(host, content);
|
||||
this.formatCodeOptions = getDefaultFormatCodeOptions(this.host);
|
||||
}
|
||||
|
||||
setFormatOptions(formatOptions: protocol.FormatOptions): void {
|
||||
@@ -51,19 +71,10 @@ namespace ts.server {
|
||||
this.isOpen = false;
|
||||
}
|
||||
|
||||
addChild(childInfo: ScriptInfo) {
|
||||
this.children.push(childInfo);
|
||||
}
|
||||
|
||||
snap() {
|
||||
return this.svc.getSnapshot();
|
||||
}
|
||||
|
||||
getText() {
|
||||
const snap = this.snap();
|
||||
return snap.getText(0, snap.getLength());
|
||||
}
|
||||
|
||||
getLineInfo(line: number) {
|
||||
const snap = this.snap();
|
||||
return snap.index.lineNumberToInfo(line);
|
||||
@@ -198,15 +209,6 @@ namespace ts.server {
|
||||
this.resolvedTypeReferenceDirectives.clear();
|
||||
}
|
||||
|
||||
lineAffectsRefs(filename: string, line: number) {
|
||||
const info = this.getScriptInfo(filename);
|
||||
const lineInfo = info.getLineInfo(line);
|
||||
if (lineInfo && lineInfo.text) {
|
||||
const regex = /reference|import|\/\*|\*\//;
|
||||
return regex.test(lineInfo.text);
|
||||
}
|
||||
}
|
||||
|
||||
getCompilationSettings() {
|
||||
// change this to return active project settings for file
|
||||
return this.compilationSettings;
|
||||
@@ -369,7 +371,8 @@ namespace ts.server {
|
||||
}
|
||||
|
||||
export class Project {
|
||||
compilerService: CompilerService;
|
||||
lsHost: LSHost;
|
||||
languageService: LanguageService;
|
||||
projectFilename: string;
|
||||
projectFileWatcher: FileWatcher;
|
||||
directoryWatcher: FileWatcher;
|
||||
@@ -381,12 +384,22 @@ namespace ts.server {
|
||||
/** Used for configured projects which may have multiple open roots */
|
||||
openRefCount = 0;
|
||||
|
||||
constructor(public projectService: ProjectService, public projectOptions?: ProjectOptions) {
|
||||
constructor(public projectService: ProjectService, documentRegistry: ts.DocumentRegistry, public projectOptions?: ProjectOptions) {
|
||||
if (projectOptions && projectOptions.files) {
|
||||
// If files are listed explicitly, allow all extensions
|
||||
projectOptions.compilerOptions.allowNonTsExtensions = true;
|
||||
}
|
||||
this.compilerService = new CompilerService(this, projectOptions && projectOptions.compilerOptions);
|
||||
this.lsHost = new LSHost(this.projectService.host, this);
|
||||
if (projectOptions && projectOptions.compilerOptions) {
|
||||
this.lsHost.setCompilationSettings(projectOptions.compilerOptions);
|
||||
}
|
||||
else {
|
||||
const defaultOpts = ts.getDefaultCompilerOptions();
|
||||
defaultOpts.allowNonTsExtensions = true;
|
||||
defaultOpts.allowJs = true;
|
||||
this.lsHost.setCompilationSettings(defaultOpts);
|
||||
}
|
||||
this.languageService = ts.createLanguageService(this.lsHost, documentRegistry);
|
||||
}
|
||||
|
||||
addOpenRef() {
|
||||
@@ -403,7 +416,7 @@ namespace ts.server {
|
||||
}
|
||||
|
||||
getRootFiles() {
|
||||
return this.compilerService.host.roots.map(info => info.fileName);
|
||||
return this.lsHost.roots.map(info => info.fileName);
|
||||
}
|
||||
|
||||
getFileNames() {
|
||||
@@ -425,11 +438,11 @@ namespace ts.server {
|
||||
}
|
||||
|
||||
isRoot(info: ScriptInfo) {
|
||||
return this.compilerService.host.roots.some(root => root === info);
|
||||
return this.lsHost.roots.some(root => root === info);
|
||||
}
|
||||
|
||||
removeReferencedFile(info: ScriptInfo) {
|
||||
this.compilerService.host.removeReferencedFile(info);
|
||||
this.lsHost.removeReferencedFile(info);
|
||||
this.updateGraph();
|
||||
}
|
||||
|
||||
@@ -444,11 +457,11 @@ namespace ts.server {
|
||||
|
||||
finishGraph() {
|
||||
this.updateGraph();
|
||||
this.compilerService.languageService.getNavigateToItems(".*");
|
||||
this.languageService.getNavigateToItems(".*");
|
||||
}
|
||||
|
||||
updateGraph() {
|
||||
this.program = this.compilerService.languageService.getProgram();
|
||||
this.program = this.languageService.getProgram();
|
||||
this.updateFileMap();
|
||||
}
|
||||
|
||||
@@ -458,12 +471,12 @@ namespace ts.server {
|
||||
|
||||
// add a root file to project
|
||||
addRoot(info: ScriptInfo) {
|
||||
this.compilerService.host.addRoot(info);
|
||||
this.lsHost.addRoot(info);
|
||||
}
|
||||
|
||||
// remove a root file from project
|
||||
removeRoot(info: ScriptInfo) {
|
||||
this.compilerService.host.removeRoot(info);
|
||||
this.lsHost.removeRoot(info);
|
||||
}
|
||||
|
||||
filesToString() {
|
||||
@@ -477,7 +490,7 @@ namespace ts.server {
|
||||
this.projectOptions = projectOptions;
|
||||
if (projectOptions.compilerOptions) {
|
||||
projectOptions.compilerOptions.allowNonTsExtensions = true;
|
||||
this.compilerService.setCompilerOptions(projectOptions.compilerOptions);
|
||||
this.lsHost.setCompilationSettings(projectOptions.compilerOptions);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -535,14 +548,17 @@ namespace ts.server {
|
||||
hostConfiguration: HostConfiguration;
|
||||
timerForDetectingProjectFileListChanges: Map<any> = {};
|
||||
|
||||
documentRegistry: ts.DocumentRegistry;
|
||||
|
||||
constructor(public host: ServerHost, public psLogger: Logger, public eventHandler?: ProjectServiceEventHandler) {
|
||||
// ts.disableIncrementalParsing = true;
|
||||
this.addDefaultHostConfiguration();
|
||||
this.documentRegistry = ts.createDocumentRegistry(host.useCaseSensitiveFileNames, host.getCurrentDirectory());
|
||||
}
|
||||
|
||||
addDefaultHostConfiguration() {
|
||||
this.hostConfiguration = {
|
||||
formatCodeOptions: ts.clone(CompilerService.getDefaultFormatCodeOptions(this.host)),
|
||||
formatCodeOptions: getDefaultFormatCodeOptions(this.host),
|
||||
hostInfo: "Unknown host"
|
||||
};
|
||||
}
|
||||
@@ -686,7 +702,7 @@ namespace ts.server {
|
||||
}
|
||||
|
||||
createInferredProject(root: ScriptInfo) {
|
||||
const project = new Project(this);
|
||||
const project = new Project(this, this.documentRegistry);
|
||||
project.addRoot(root);
|
||||
|
||||
let currentPath = ts.getDirectoryPath(root.fileName);
|
||||
@@ -1299,7 +1315,7 @@ namespace ts.server {
|
||||
return errors;
|
||||
}
|
||||
else {
|
||||
const oldFileNames = project.compilerService.host.roots.map(info => info.fileName);
|
||||
const oldFileNames = project.lsHost.roots.map(info => info.fileName);
|
||||
const newFileNames = ts.filter(projectOptions.files, f => this.host.fileExists(f));
|
||||
const fileNamesToRemove = oldFileNames.filter(f => newFileNames.indexOf(f) < 0);
|
||||
const fileNamesToAdd = newFileNames.filter(f => oldFileNames.indexOf(f) < 0);
|
||||
@@ -1343,17 +1359,16 @@ namespace ts.server {
|
||||
}
|
||||
|
||||
createProject(projectFilename: string, projectOptions?: ProjectOptions) {
|
||||
const project = new Project(this, projectOptions);
|
||||
const project = new Project(this, this.documentRegistry, projectOptions);
|
||||
project.projectFilename = projectFilename;
|
||||
return project;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export class CompilerService {
|
||||
export class CompilerServic1e {
|
||||
host: LSHost;
|
||||
languageService: ts.LanguageService;
|
||||
classifier: ts.Classifier;
|
||||
settings: ts.CompilerOptions;
|
||||
documentRegistry = ts.createDocumentRegistry();
|
||||
|
||||
@@ -1369,38 +1384,12 @@ namespace ts.server {
|
||||
this.setCompilerOptions(defaultOpts);
|
||||
}
|
||||
this.languageService = ts.createLanguageService(this.host, this.documentRegistry);
|
||||
this.classifier = ts.createClassifier();
|
||||
}
|
||||
|
||||
setCompilerOptions(opt: ts.CompilerOptions) {
|
||||
this.settings = opt;
|
||||
this.host.setCompilationSettings(opt);
|
||||
}
|
||||
|
||||
isExternalModule(filename: string): boolean {
|
||||
const sourceFile = this.languageService.getNonBoundSourceFile(filename);
|
||||
return ts.isExternalModule(sourceFile);
|
||||
}
|
||||
|
||||
static getDefaultFormatCodeOptions(host: ServerHost): ts.FormatCodeOptions {
|
||||
return ts.clone({
|
||||
IndentSize: 4,
|
||||
TabSize: 4,
|
||||
NewLineCharacter: host.newLine || "\n",
|
||||
ConvertTabsToSpaces: true,
|
||||
IndentStyle: ts.IndentStyle.Smart,
|
||||
InsertSpaceAfterCommaDelimiter: true,
|
||||
InsertSpaceAfterSemicolonInForStatements: true,
|
||||
InsertSpaceBeforeAndAfterBinaryOperators: true,
|
||||
InsertSpaceAfterKeywordsInControlFlowStatements: true,
|
||||
InsertSpaceAfterFunctionKeywordForAnonymousFunctions: false,
|
||||
InsertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis: false,
|
||||
InsertSpaceAfterOpeningAndBeforeClosingNonemptyBrackets: false,
|
||||
InsertSpaceAfterOpeningAndBeforeClosingTemplateStringBraces: false,
|
||||
PlaceOpenBraceOnNewLineForFunctions: false,
|
||||
PlaceOpenBraceOnNewLineForControlBlocks: false,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export interface LineCollection {
|
||||
|
||||
@@ -70,8 +70,8 @@ namespace ts.server {
|
||||
|
||||
function formatDiag(fileName: string, project: Project, diag: ts.Diagnostic): protocol.Diagnostic {
|
||||
return {
|
||||
start: project.compilerService.host.positionToLineOffset(fileName, diag.start),
|
||||
end: project.compilerService.host.positionToLineOffset(fileName, diag.start + diag.length),
|
||||
start: project.lsHost.positionToLineOffset(fileName, diag.start),
|
||||
end: project.lsHost.positionToLineOffset(fileName, diag.start + diag.length),
|
||||
text: ts.flattenDiagnosticMessageText(diag.messageText, "\n")
|
||||
};
|
||||
}
|
||||
@@ -236,7 +236,7 @@ namespace ts.server {
|
||||
|
||||
private semanticCheck(file: string, project: Project) {
|
||||
try {
|
||||
const diags = project.compilerService.languageService.getSemanticDiagnostics(file);
|
||||
const diags = project.languageService.getSemanticDiagnostics(file);
|
||||
|
||||
if (diags) {
|
||||
const bakedDiags = diags.map((diag) => formatDiag(file, project, diag));
|
||||
@@ -250,7 +250,7 @@ namespace ts.server {
|
||||
|
||||
private syntacticCheck(file: string, project: Project) {
|
||||
try {
|
||||
const diags = project.compilerService.languageService.getSyntacticDiagnostics(file);
|
||||
const diags = project.languageService.getSyntacticDiagnostics(file);
|
||||
if (diags) {
|
||||
const bakedDiags = diags.map((diag) => formatDiag(file, project, diag));
|
||||
this.event({ file: file, diagnostics: bakedDiags }, "syntaxDiag");
|
||||
@@ -317,18 +317,18 @@ namespace ts.server {
|
||||
throw Errors.NoProject;
|
||||
}
|
||||
|
||||
const compilerService = project.compilerService;
|
||||
const position = compilerService.host.lineOffsetToPosition(file, line, offset);
|
||||
const lsHost = project.lsHost;
|
||||
const position = lsHost.lineOffsetToPosition(file, line, offset);
|
||||
|
||||
const definitions = compilerService.languageService.getDefinitionAtPosition(file, position);
|
||||
const definitions = project.languageService.getDefinitionAtPosition(file, position);
|
||||
if (!definitions) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
return definitions.map(def => ({
|
||||
file: def.fileName,
|
||||
start: compilerService.host.positionToLineOffset(def.fileName, def.textSpan.start),
|
||||
end: compilerService.host.positionToLineOffset(def.fileName, ts.textSpanEnd(def.textSpan))
|
||||
start: lsHost.positionToLineOffset(def.fileName, def.textSpan.start),
|
||||
end: lsHost.positionToLineOffset(def.fileName, ts.textSpanEnd(def.textSpan))
|
||||
}));
|
||||
}
|
||||
|
||||
@@ -339,18 +339,18 @@ namespace ts.server {
|
||||
throw Errors.NoProject;
|
||||
}
|
||||
|
||||
const compilerService = project.compilerService;
|
||||
const position = compilerService.host.lineOffsetToPosition(file, line, offset);
|
||||
const lsHost = project.lsHost;
|
||||
const position = lsHost.lineOffsetToPosition(file, line, offset);
|
||||
|
||||
const definitions = compilerService.languageService.getTypeDefinitionAtPosition(file, position);
|
||||
const definitions = project.languageService.getTypeDefinitionAtPosition(file, position);
|
||||
if (!definitions) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
return definitions.map(def => ({
|
||||
file: def.fileName,
|
||||
start: compilerService.host.positionToLineOffset(def.fileName, def.textSpan.start),
|
||||
end: compilerService.host.positionToLineOffset(def.fileName, ts.textSpanEnd(def.textSpan))
|
||||
start: lsHost.positionToLineOffset(def.fileName, def.textSpan.start),
|
||||
end: lsHost.positionToLineOffset(def.fileName, ts.textSpanEnd(def.textSpan))
|
||||
}));
|
||||
}
|
||||
|
||||
@@ -362,10 +362,10 @@ namespace ts.server {
|
||||
throw Errors.NoProject;
|
||||
}
|
||||
|
||||
const { compilerService } = project;
|
||||
const position = compilerService.host.lineOffsetToPosition(fileName, line, offset);
|
||||
const { lsHost } = project;
|
||||
const position = lsHost.lineOffsetToPosition(fileName, line, offset);
|
||||
|
||||
const occurrences = compilerService.languageService.getOccurrencesAtPosition(fileName, position);
|
||||
const occurrences = project.languageService.getOccurrencesAtPosition(fileName, position);
|
||||
|
||||
if (!occurrences) {
|
||||
return undefined;
|
||||
@@ -373,8 +373,8 @@ namespace ts.server {
|
||||
|
||||
return occurrences.map(occurrence => {
|
||||
const { fileName, isWriteAccess, textSpan } = occurrence;
|
||||
const start = compilerService.host.positionToLineOffset(fileName, textSpan.start);
|
||||
const end = compilerService.host.positionToLineOffset(fileName, ts.textSpanEnd(textSpan));
|
||||
const start = lsHost.positionToLineOffset(fileName, textSpan.start);
|
||||
const end = lsHost.positionToLineOffset(fileName, ts.textSpanEnd(textSpan));
|
||||
return {
|
||||
start,
|
||||
end,
|
||||
@@ -392,10 +392,10 @@ namespace ts.server {
|
||||
throw Errors.NoProject;
|
||||
}
|
||||
|
||||
const { compilerService } = project;
|
||||
const position = compilerService.host.lineOffsetToPosition(fileName, line, offset);
|
||||
const { lsHost } = project;
|
||||
const position = lsHost.lineOffsetToPosition(fileName, line, offset);
|
||||
|
||||
const documentHighlights = compilerService.languageService.getDocumentHighlights(fileName, position, filesToSearch);
|
||||
const documentHighlights = project.languageService.getDocumentHighlights(fileName, position, filesToSearch);
|
||||
|
||||
if (!documentHighlights) {
|
||||
return undefined;
|
||||
@@ -413,8 +413,8 @@ namespace ts.server {
|
||||
|
||||
function convertHighlightSpan(highlightSpan: ts.HighlightSpan): ts.server.protocol.HighlightSpan {
|
||||
const { textSpan, kind } = highlightSpan;
|
||||
const start = compilerService.host.positionToLineOffset(fileName, textSpan.start);
|
||||
const end = compilerService.host.positionToLineOffset(fileName, ts.textSpanEnd(textSpan));
|
||||
const start = lsHost.positionToLineOffset(fileName, textSpan.start);
|
||||
const end = lsHost.positionToLineOffset(fileName, ts.textSpanEnd(textSpan));
|
||||
return { start, end, kind };
|
||||
}
|
||||
}
|
||||
@@ -445,9 +445,9 @@ namespace ts.server {
|
||||
|
||||
const defaultProject = projects[0];
|
||||
// The rename info should be the same for every project
|
||||
const defaultProjectCompilerService = defaultProject.compilerService;
|
||||
const position = defaultProjectCompilerService.host.lineOffsetToPosition(file, line, offset);
|
||||
const renameInfo = defaultProjectCompilerService.languageService.getRenameInfo(file, position);
|
||||
const lsHost = defaultProject.lsHost;
|
||||
const position = lsHost.lineOffsetToPosition(file, line, offset);
|
||||
const renameInfo = defaultProject.languageService.getRenameInfo(file, position);
|
||||
if (!renameInfo) {
|
||||
return undefined;
|
||||
}
|
||||
@@ -462,16 +462,15 @@ namespace ts.server {
|
||||
const fileSpans = combineProjectOutput(
|
||||
projects,
|
||||
(project: Project) => {
|
||||
const compilerService = project.compilerService;
|
||||
const renameLocations = compilerService.languageService.findRenameLocations(file, position, findInStrings, findInComments);
|
||||
const renameLocations = project.languageService.findRenameLocations(file, position, findInStrings, findInComments);
|
||||
if (!renameLocations) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return renameLocations.map(location => (<protocol.FileSpan>{
|
||||
file: location.fileName,
|
||||
start: compilerService.host.positionToLineOffset(location.fileName, location.textSpan.start),
|
||||
end: compilerService.host.positionToLineOffset(location.fileName, ts.textSpanEnd(location.textSpan)),
|
||||
start: project.lsHost.positionToLineOffset(location.fileName, location.textSpan.start),
|
||||
end: project.lsHost.positionToLineOffset(location.fileName, ts.textSpanEnd(location.textSpan)),
|
||||
}));
|
||||
},
|
||||
compareRenameLocation,
|
||||
@@ -526,35 +525,35 @@ namespace ts.server {
|
||||
}
|
||||
|
||||
const defaultProject = projects[0];
|
||||
const position = defaultProject.compilerService.host.lineOffsetToPosition(file, line, offset);
|
||||
const nameInfo = defaultProject.compilerService.languageService.getQuickInfoAtPosition(file, position);
|
||||
const lsHost = defaultProject.lsHost;
|
||||
const position = lsHost.lineOffsetToPosition(file, line, offset);
|
||||
const nameInfo = defaultProject.languageService.getQuickInfoAtPosition(file, position);
|
||||
if (!nameInfo) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
const displayString = ts.displayPartsToString(nameInfo.displayParts);
|
||||
const nameSpan = nameInfo.textSpan;
|
||||
const nameColStart = defaultProject.compilerService.host.positionToLineOffset(file, nameSpan.start).offset;
|
||||
const nameText = defaultProject.compilerService.host.getScriptSnapshot(file).getText(nameSpan.start, ts.textSpanEnd(nameSpan));
|
||||
const nameColStart = lsHost.positionToLineOffset(file, nameSpan.start).offset;
|
||||
const nameText = lsHost.getScriptSnapshot(file).getText(nameSpan.start, ts.textSpanEnd(nameSpan));
|
||||
const refs = combineProjectOutput<protocol.ReferencesResponseItem>(
|
||||
projects,
|
||||
(project: Project) => {
|
||||
const compilerService = project.compilerService;
|
||||
const references = compilerService.languageService.getReferencesAtPosition(file, position);
|
||||
const references = project.languageService.getReferencesAtPosition(file, position);
|
||||
if (!references) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return references.map(ref => {
|
||||
const start = compilerService.host.positionToLineOffset(ref.fileName, ref.textSpan.start);
|
||||
const refLineSpan = compilerService.host.lineToTextSpan(ref.fileName, start.line - 1);
|
||||
const snap = compilerService.host.getScriptSnapshot(ref.fileName);
|
||||
const start = project.lsHost.positionToLineOffset(ref.fileName, ref.textSpan.start);
|
||||
const refLineSpan = project.lsHost.lineToTextSpan(ref.fileName, start.line - 1);
|
||||
const snap = project.lsHost.getScriptSnapshot(ref.fileName);
|
||||
const lineText = snap.getText(refLineSpan.start, ts.textSpanEnd(refLineSpan)).replace(/\r|\n/g, "");
|
||||
return {
|
||||
file: ref.fileName,
|
||||
start: start,
|
||||
lineText: lineText,
|
||||
end: compilerService.host.positionToLineOffset(ref.fileName, ts.textSpanEnd(ref.textSpan)),
|
||||
end: project.lsHost.positionToLineOffset(ref.fileName, ts.textSpanEnd(ref.textSpan)),
|
||||
isWriteAccess: ref.isWriteAccess
|
||||
};
|
||||
});
|
||||
@@ -599,9 +598,9 @@ namespace ts.server {
|
||||
throw Errors.NoProject;
|
||||
}
|
||||
|
||||
const compilerService = project.compilerService;
|
||||
const position = compilerService.host.lineOffsetToPosition(file, line, offset);
|
||||
const quickInfo = compilerService.languageService.getQuickInfoAtPosition(file, position);
|
||||
const lsHost = project.lsHost;
|
||||
const position = lsHost.lineOffsetToPosition(file, line, offset);
|
||||
const quickInfo = project.languageService.getQuickInfoAtPosition(file, position);
|
||||
if (!quickInfo) {
|
||||
return undefined;
|
||||
}
|
||||
@@ -611,8 +610,8 @@ namespace ts.server {
|
||||
return {
|
||||
kind: quickInfo.kind,
|
||||
kindModifiers: quickInfo.kindModifiers,
|
||||
start: compilerService.host.positionToLineOffset(file, quickInfo.textSpan.start),
|
||||
end: compilerService.host.positionToLineOffset(file, ts.textSpanEnd(quickInfo.textSpan)),
|
||||
start: lsHost.positionToLineOffset(file, quickInfo.textSpan.start),
|
||||
end: lsHost.positionToLineOffset(file, ts.textSpanEnd(quickInfo.textSpan)),
|
||||
displayString: displayString,
|
||||
documentation: docString,
|
||||
};
|
||||
@@ -625,12 +624,12 @@ namespace ts.server {
|
||||
throw Errors.NoProject;
|
||||
}
|
||||
|
||||
const compilerService = project.compilerService;
|
||||
const startPosition = compilerService.host.lineOffsetToPosition(file, line, offset);
|
||||
const endPosition = compilerService.host.lineOffsetToPosition(file, endLine, endOffset);
|
||||
const lsHost = project.lsHost;
|
||||
const startPosition = lsHost.lineOffsetToPosition(file, line, offset);
|
||||
const endPosition = lsHost.lineOffsetToPosition(file, endLine, endOffset);
|
||||
|
||||
// TODO: avoid duplicate code (with formatonkey)
|
||||
const edits = compilerService.languageService.getFormattingEditsForRange(file, startPosition, endPosition,
|
||||
const edits = project.languageService.getFormattingEditsForRange(file, startPosition, endPosition,
|
||||
this.projectService.getFormatCodeOptions(file));
|
||||
if (!edits) {
|
||||
return undefined;
|
||||
@@ -638,8 +637,8 @@ namespace ts.server {
|
||||
|
||||
return edits.map((edit) => {
|
||||
return {
|
||||
start: compilerService.host.positionToLineOffset(file, edit.span.start),
|
||||
end: compilerService.host.positionToLineOffset(file, ts.textSpanEnd(edit.span)),
|
||||
start: lsHost.positionToLineOffset(file, edit.span.start),
|
||||
end: lsHost.positionToLineOffset(file, ts.textSpanEnd(edit.span)),
|
||||
newText: edit.newText ? edit.newText : ""
|
||||
};
|
||||
});
|
||||
@@ -653,10 +652,10 @@ namespace ts.server {
|
||||
throw Errors.NoProject;
|
||||
}
|
||||
|
||||
const compilerService = project.compilerService;
|
||||
const position = compilerService.host.lineOffsetToPosition(file, line, offset);
|
||||
const lsHost = project.lsHost;
|
||||
const position = lsHost.lineOffsetToPosition(file, line, offset);
|
||||
const formatOptions = this.projectService.getFormatCodeOptions(file);
|
||||
const edits = compilerService.languageService.getFormattingEditsAfterKeystroke(file, position, key,
|
||||
const edits = project.languageService.getFormattingEditsAfterKeystroke(file, position, key,
|
||||
formatOptions);
|
||||
// Check whether we should auto-indent. This will be when
|
||||
// the position is on a line containing only whitespace.
|
||||
@@ -665,7 +664,7 @@ namespace ts.server {
|
||||
// only to the previous line. If all this is true, then
|
||||
// add edits necessary to properly indent the current line.
|
||||
if ((key == "\n") && ((!edits) || (edits.length === 0) || allEditsBeforePos(edits, position))) {
|
||||
const scriptInfo = compilerService.host.getScriptInfo(file);
|
||||
const scriptInfo = lsHost.getScriptInfo(file);
|
||||
if (scriptInfo) {
|
||||
const lineInfo = scriptInfo.getLineInfo(line);
|
||||
if (lineInfo && (lineInfo.leaf) && (lineInfo.leaf.text)) {
|
||||
@@ -679,7 +678,7 @@ namespace ts.server {
|
||||
ConvertTabsToSpaces: formatOptions.ConvertTabsToSpaces,
|
||||
IndentStyle: ts.IndentStyle.Smart,
|
||||
};
|
||||
const preferredIndent = compilerService.languageService.getIndentationAtPosition(file, position, editorOptions);
|
||||
const preferredIndent = project.languageService.getIndentationAtPosition(file, position, editorOptions);
|
||||
let hasIndent = 0;
|
||||
let i: number, len: number;
|
||||
for (i = 0, len = lineText.length; i < len; i++) {
|
||||
@@ -712,9 +711,9 @@ namespace ts.server {
|
||||
|
||||
return edits.map((edit) => {
|
||||
return {
|
||||
start: compilerService.host.positionToLineOffset(file,
|
||||
start: lsHost.positionToLineOffset(file,
|
||||
edit.span.start),
|
||||
end: compilerService.host.positionToLineOffset(file,
|
||||
end: lsHost.positionToLineOffset(file,
|
||||
ts.textSpanEnd(edit.span)),
|
||||
newText: edit.newText ? edit.newText : ""
|
||||
};
|
||||
@@ -731,10 +730,10 @@ namespace ts.server {
|
||||
throw Errors.NoProject;
|
||||
}
|
||||
|
||||
const compilerService = project.compilerService;
|
||||
const position = compilerService.host.lineOffsetToPosition(file, line, offset);
|
||||
const lsHost = project.lsHost;
|
||||
const position = lsHost.lineOffsetToPosition(file, line, offset);
|
||||
|
||||
const completions = compilerService.languageService.getCompletionsAtPosition(file, position);
|
||||
const completions = project.languageService.getCompletionsAtPosition(file, position);
|
||||
if (!completions) {
|
||||
return undefined;
|
||||
}
|
||||
@@ -755,11 +754,11 @@ namespace ts.server {
|
||||
throw Errors.NoProject;
|
||||
}
|
||||
|
||||
const compilerService = project.compilerService;
|
||||
const position = compilerService.host.lineOffsetToPosition(file, line, offset);
|
||||
const lsHost = project.lsHost;
|
||||
const position = lsHost.lineOffsetToPosition(file, line, offset);
|
||||
|
||||
return entryNames.reduce((accum: protocol.CompletionEntryDetails[], entryName: string) => {
|
||||
const details = compilerService.languageService.getCompletionEntryDetails(file, position, entryName);
|
||||
const details = project.languageService.getCompletionEntryDetails(file, position, entryName);
|
||||
if (details) {
|
||||
accum.push(details);
|
||||
}
|
||||
@@ -774,9 +773,9 @@ namespace ts.server {
|
||||
throw Errors.NoProject;
|
||||
}
|
||||
|
||||
const compilerService = project.compilerService;
|
||||
const position = compilerService.host.lineOffsetToPosition(file, line, offset);
|
||||
const helpItems = compilerService.languageService.getSignatureHelpItems(file, position);
|
||||
const lsHost = project.lsHost;
|
||||
const position = lsHost.lineOffsetToPosition(file, line, offset);
|
||||
const helpItems = project.languageService.getSignatureHelpItems(file, position);
|
||||
if (!helpItems) {
|
||||
return undefined;
|
||||
}
|
||||
@@ -785,8 +784,8 @@ namespace ts.server {
|
||||
const result: protocol.SignatureHelpItems = {
|
||||
items: helpItems.items,
|
||||
applicableSpan: {
|
||||
start: compilerService.host.positionToLineOffset(file, span.start),
|
||||
end: compilerService.host.positionToLineOffset(file, span.start + span.length)
|
||||
start: lsHost.positionToLineOffset(file, span.start),
|
||||
end: lsHost.positionToLineOffset(file, span.start + span.length)
|
||||
},
|
||||
selectedItemIndex: helpItems.selectedItemIndex,
|
||||
argumentIndex: helpItems.argumentIndex,
|
||||
@@ -815,11 +814,11 @@ namespace ts.server {
|
||||
const file = ts.normalizePath(fileName);
|
||||
const project = this.projectService.getProjectForFile(file);
|
||||
if (project) {
|
||||
const compilerService = project.compilerService;
|
||||
const start = compilerService.host.lineOffsetToPosition(file, line, offset);
|
||||
const end = compilerService.host.lineOffsetToPosition(file, endLine, endOffset);
|
||||
const lsHost = project.lsHost;
|
||||
const start = lsHost.lineOffsetToPosition(file, line, offset);
|
||||
const end = lsHost.lineOffsetToPosition(file, endLine, endOffset);
|
||||
if (start >= 0) {
|
||||
compilerService.host.editScript(file, start, end, insertString);
|
||||
lsHost.editScript(file, start, end, insertString);
|
||||
this.changeSeq++;
|
||||
}
|
||||
this.updateProjectStructure(this.changeSeq, (n) => n === this.changeSeq);
|
||||
@@ -833,7 +832,7 @@ namespace ts.server {
|
||||
if (project) {
|
||||
this.changeSeq++;
|
||||
// make sure no changes happen before this one is finished
|
||||
project.compilerService.host.reloadScript(file, tmpfile, () => {
|
||||
project.lsHost.reloadScript(file, tmpfile, () => {
|
||||
this.output(undefined, CommandNames.Reload, reqSeq);
|
||||
});
|
||||
}
|
||||
@@ -845,7 +844,7 @@ namespace ts.server {
|
||||
|
||||
const project = this.projectService.getProjectForFile(file);
|
||||
if (project) {
|
||||
project.compilerService.host.saveTo(file, tmpfile);
|
||||
project.lsHost.saveTo(file, tmpfile);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -862,15 +861,15 @@ namespace ts.server {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
const compilerService = project.compilerService;
|
||||
const lsHost = project.lsHost;
|
||||
|
||||
return items.map(item => ({
|
||||
text: item.text,
|
||||
kind: item.kind,
|
||||
kindModifiers: item.kindModifiers,
|
||||
spans: item.spans.map(span => ({
|
||||
start: compilerService.host.positionToLineOffset(fileName, span.start),
|
||||
end: compilerService.host.positionToLineOffset(fileName, ts.textSpanEnd(span))
|
||||
start: lsHost.positionToLineOffset(fileName, span.start),
|
||||
end: lsHost.positionToLineOffset(fileName, ts.textSpanEnd(span))
|
||||
})),
|
||||
childItems: this.decorateNavigationBarItem(project, fileName, item.childItems)
|
||||
}));
|
||||
@@ -883,8 +882,7 @@ namespace ts.server {
|
||||
throw Errors.NoProject;
|
||||
}
|
||||
|
||||
const compilerService = project.compilerService;
|
||||
const items = compilerService.languageService.getNavigationBarItems(file);
|
||||
const items = project.languageService.getNavigationBarItems(file);
|
||||
if (!items) {
|
||||
return undefined;
|
||||
}
|
||||
@@ -904,15 +902,14 @@ namespace ts.server {
|
||||
const allNavToItems = combineProjectOutput(
|
||||
projects,
|
||||
(project: Project) => {
|
||||
const compilerService = project.compilerService;
|
||||
const navItems = compilerService.languageService.getNavigateToItems(searchValue, maxResultCount);
|
||||
const navItems = project.languageService.getNavigateToItems(searchValue, maxResultCount);
|
||||
if (!navItems) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return navItems.map((navItem) => {
|
||||
const start = compilerService.host.positionToLineOffset(navItem.fileName, navItem.textSpan.start);
|
||||
const end = compilerService.host.positionToLineOffset(navItem.fileName, ts.textSpanEnd(navItem.textSpan));
|
||||
const start = project.lsHost.positionToLineOffset(navItem.fileName, navItem.textSpan.start);
|
||||
const end = project.lsHost.positionToLineOffset(navItem.fileName, ts.textSpanEnd(navItem.textSpan));
|
||||
const bakedItem: protocol.NavtoItem = {
|
||||
name: navItem.name,
|
||||
kind: navItem.kind,
|
||||
@@ -958,17 +955,17 @@ namespace ts.server {
|
||||
throw Errors.NoProject;
|
||||
}
|
||||
|
||||
const compilerService = project.compilerService;
|
||||
const position = compilerService.host.lineOffsetToPosition(file, line, offset);
|
||||
const lsHost = project.lsHost;
|
||||
const position = lsHost.lineOffsetToPosition(file, line, offset);
|
||||
|
||||
const spans = compilerService.languageService.getBraceMatchingAtPosition(file, position);
|
||||
const spans = project.languageService.getBraceMatchingAtPosition(file, position);
|
||||
if (!spans) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
return spans.map(span => ({
|
||||
start: compilerService.host.positionToLineOffset(file, span.start),
|
||||
end: compilerService.host.positionToLineOffset(file, span.start + span.length)
|
||||
start: lsHost.positionToLineOffset(file, span.start),
|
||||
end: lsHost.positionToLineOffset(file, span.start + span.length)
|
||||
}));
|
||||
}
|
||||
|
||||
|
||||
@@ -105,7 +105,7 @@ namespace ts {
|
||||
const { project, rootScriptInfo } = createProject(root.name, serverHost);
|
||||
|
||||
// ensure that imported file was found
|
||||
let diags = project.compilerService.languageService.getSemanticDiagnostics(imported.name);
|
||||
let diags = project.languageService.getSemanticDiagnostics(imported.name);
|
||||
assert.equal(diags.length, 1);
|
||||
|
||||
const originalFileExists = serverHost.fileExists;
|
||||
@@ -120,7 +120,7 @@ namespace ts {
|
||||
var x: string = 1;`;
|
||||
rootScriptInfo.editContent(0, rootScriptInfo.content.length, newContent);
|
||||
// trigger synchronization to make sure that import will be fetched from the cache
|
||||
diags = project.compilerService.languageService.getSemanticDiagnostics(imported.name);
|
||||
diags = project.languageService.getSemanticDiagnostics(imported.name);
|
||||
// ensure file has correct number of errors after edit
|
||||
assert.equal(diags.length, 1);
|
||||
}
|
||||
@@ -139,7 +139,7 @@ namespace ts {
|
||||
|
||||
try {
|
||||
// trigger synchronization to make sure that LSHost will try to find 'f2' module on disk
|
||||
project.compilerService.languageService.getSemanticDiagnostics(imported.name);
|
||||
project.languageService.getSemanticDiagnostics(imported.name);
|
||||
assert.isTrue(false, `should not find file '${imported.name}'`);
|
||||
}
|
||||
catch (e) {
|
||||
@@ -160,7 +160,7 @@ namespace ts {
|
||||
|
||||
const newContent = `import {x} from "f1"`;
|
||||
rootScriptInfo.editContent(0, rootScriptInfo.content.length, newContent);
|
||||
project.compilerService.languageService.getSemanticDiagnostics(imported.name);
|
||||
project.languageService.getSemanticDiagnostics(imported.name);
|
||||
assert.isTrue(fileExistsCalled);
|
||||
|
||||
// setting compiler options discards module resolution cache
|
||||
@@ -171,7 +171,7 @@ namespace ts {
|
||||
opts.compilerOptions.target = ts.ScriptTarget.ES5;
|
||||
project.setProjectOptions(opts);
|
||||
|
||||
project.compilerService.languageService.getSemanticDiagnostics(imported.name);
|
||||
project.languageService.getSemanticDiagnostics(imported.name);
|
||||
assert.isTrue(fileExistsCalled);
|
||||
}
|
||||
});
|
||||
@@ -205,7 +205,7 @@ namespace ts {
|
||||
|
||||
const { project, rootScriptInfo } = createProject(root.name, serverHost);
|
||||
|
||||
let diags = project.compilerService.languageService.getSemanticDiagnostics(root.name);
|
||||
let diags = project.languageService.getSemanticDiagnostics(root.name);
|
||||
assert.isTrue(fileExistsCalledForBar, "'fileExists' should be called");
|
||||
assert.isTrue(diags.length === 1, "one diagnostic expected");
|
||||
assert.isTrue(typeof diags[0].messageText === "string" && ((<string>diags[0].messageText).indexOf("Cannot find module") === 0), "should be 'cannot find module' message");
|
||||
@@ -215,7 +215,7 @@ namespace ts {
|
||||
fileExistsCalledForBar = false;
|
||||
rootScriptInfo.editContent(0, rootScriptInfo.content.length, `import {y} from "bar"`);
|
||||
|
||||
diags = project.compilerService.languageService.getSemanticDiagnostics(root.name);
|
||||
diags = project.languageService.getSemanticDiagnostics(root.name);
|
||||
assert.isTrue(fileExistsCalledForBar, "'fileExists' should be called");
|
||||
assert.isTrue(diags.length === 0);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user