Skip to content

Commit

Permalink
refactor(language-server): rename functions for clarity and consistency
Browse files Browse the repository at this point in the history
  • Loading branch information
johnsoncodehk committed Aug 21, 2024
1 parent 1adcf09 commit 5b319c8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
28 changes: 14 additions & 14 deletions packages/language-server/lib/project/typescriptProject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,11 @@ export function createTypeScriptProject(
dir = path.dirname(dir);
}

await prepareClosestootParsedCommandLine();
await prepareClosestootCommandLine();

return await findDirectIncludeTsconfig() ?? await findIndirectReferenceTsconfig();

async function prepareClosestootParsedCommandLine() {
async function prepareClosestootCommandLine() {

let matches: string[] = [];

Expand All @@ -121,7 +121,7 @@ export function createTypeScriptProject(
matches = matches.sort((a, b) => sortTSConfigs(fileName, a, b));

if (matches.length) {
await getParsedCommandLine(matches[0]);
await getCommandLine(matches[0]);
}
}
function findIndirectReferenceTsconfig() {
Expand All @@ -135,8 +135,8 @@ export function createTypeScriptProject(
function findDirectIncludeTsconfig() {
return findTSConfig(async tsconfig => {
const map = createUriMap<boolean>();
const parsedCommandLine = await getParsedCommandLine(tsconfig);
for (const fileName of parsedCommandLine?.fileNames ?? []) {
const commandLine = await getCommandLine(tsconfig);
for (const fileName of commandLine?.fileNames ?? []) {
const uri = uriConverter.asUri(fileName);
map.set(uri, true);
}
Expand All @@ -152,7 +152,7 @@ export function createTypeScriptProject(
const project = await configProjects.get(tsconfigUri);
if (project) {

let chains = await getReferencesChains(project.getParsedCommandLine(), rootTsConfig, []);
let chains = await getReferencesChains(project.getCommandLine(), rootTsConfig, []);

// This is to be consistent with tsserver behavior
chains = chains.reverse();
Expand All @@ -174,13 +174,13 @@ export function createTypeScriptProject(
}
}
}
async function getReferencesChains(parsedCommandLine: ts.ParsedCommandLine, tsConfig: string, before: string[]) {
async function getReferencesChains(commandLine: ts.ParsedCommandLine, tsConfig: string, before: string[]) {

if (parsedCommandLine.projectReferences?.length) {
if (commandLine.projectReferences?.length) {

const newChains: string[][] = [];

for (const projectReference of parsedCommandLine.projectReferences) {
for (const projectReference of commandLine.projectReferences) {

let tsConfigPath = projectReference.path.replace(/\\/g, '/');

Expand All @@ -201,9 +201,9 @@ export function createTypeScriptProject(
newChains.push(before.slice(0, Math.max(beforeIndex, 1)));
}
else {
const referenceParsedCommandLine = await getParsedCommandLine(tsConfigPath);
if (referenceParsedCommandLine) {
for (const chain of await getReferencesChains(referenceParsedCommandLine, tsConfigPath, [...before, tsConfig])) {
const referenceCommandLine = await getCommandLine(tsConfigPath);
if (referenceCommandLine) {
for (const chain of await getReferencesChains(referenceCommandLine, tsConfigPath, [...before, tsConfig])) {
newChains.push(chain);
}
}
Expand All @@ -216,9 +216,9 @@ export function createTypeScriptProject(
return [[...before, tsConfig]];
}
}
async function getParsedCommandLine(tsConfig: string) {
async function getCommandLine(tsConfig: string) {
const project = await getOrCreateConfiguredProject(server, tsConfig);
return project?.getParsedCommandLine();
return project?.getCommandLine();
}
}

Expand Down
4 changes: 2 additions & 2 deletions packages/language-server/lib/project/typescriptProjectLs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import type { LanguageServer } from '../types';

export interface TypeScriptProjectLS {
tryAddFile(fileName: string): void;
getParsedCommandLine(): ts.ParsedCommandLine;
getCommandLine(): ts.ParsedCommandLine;
languageService: LanguageService;
dispose(): void;
}
Expand Down Expand Up @@ -159,7 +159,7 @@ export async function createTypeScriptLS(
docSaveWatcher.dispose();
docChangeWatcher.dispose();
},
getParsedCommandLine: () => parsedCommandLine,
getCommandLine: () => parsedCommandLine,
};

function updateFsCacheFromSyncedDocument(document: SnapshotDocument) {
Expand Down

0 comments on commit 5b319c8

Please sign in to comment.