Skip to content

Commit

Permalink
updates
Browse files Browse the repository at this point in the history
  • Loading branch information
johnsoncodehk committed Nov 17, 2023
1 parent aa2ddd4 commit fc3c13c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 14 deletions.
8 changes: 4 additions & 4 deletions packages/astro-check/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,20 +44,20 @@ export async function check(flags: Partial<Flags>): Promise<boolean | void> {
// Dynamically get the list of extensions to watch from the files already included in the project
const checkedExtensions = Array.from(
new Set(
checker.project.typescript!.projectHost.getScriptFileNames().map((fileName) => path.extname(fileName))
checker.linter.projectHost.getScriptFileNames().map((fileName) => path.extname(fileName))
)
);
createWatcher(workspaceRoot, checkedExtensions)
.on('add', (fileName) => {
checker.project.fileCreated(fileName);
checker.linter.fileCreated(fileName);
update();
})
.on('unlink', (fileName) => {
checker.project.fileDeleted(fileName);
checker.linter.fileDeleted(fileName);
update();
})
.on('change', (fileName) => {
checker.project.fileUpdated(fileName);
checker.linter.fileUpdated(fileName);
update();
});
}
Expand Down
16 changes: 6 additions & 10 deletions packages/language-server/src/check.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ export interface CheckResult {

export class AstroCheck {
private ts!: typeof import('typescript/lib/tsserverlibrary.js');
public project!: kit.Project;
private linter!: ReturnType<typeof kit.createLinter>;
public linter!: ReturnType<typeof kit['createTypeScriptChecker']>;

constructor(
private readonly workspacePath: string,
Expand Down Expand Up @@ -61,7 +60,7 @@ export class AstroCheck {
| undefined;
}): Promise<CheckResult> {
const files =
fileNames !== undefined ? fileNames : this.project.typescript!.projectHost.getScriptFileNames();
fileNames !== undefined ? fileNames : this.linter.projectHost.getScriptFileNames();

const result: CheckResult = {
status: undefined,
Expand Down Expand Up @@ -98,7 +97,7 @@ export class AstroCheck {
console.info(errorText);
}

const fileSnapshot = this.project.typescript!.projectHost.getScriptSnapshot(file);
const fileSnapshot = this.linter.projectHost.getScriptSnapshot(file);
const fileContent = fileSnapshot?.getText(0, fileSnapshot.getLength());

result.fileResult.push({
Expand Down Expand Up @@ -130,7 +129,7 @@ export class AstroCheck {
this.ts = this.typescriptPath ? require(this.typescriptPath) : require('typescript');
const tsconfigPath = this.getTsconfig();

const languages: kit.Language[] = [
const languages = [
getLanguageModule(getAstroInstall([this.workspacePath]), this.ts),
getSvelteLanguageModule(),
getVueLanguageModule(),
Expand All @@ -139,25 +138,22 @@ export class AstroCheck {
createTypeScriptService(),
createAstroService(),
];
const env = kit.createServiceEnvironment();

if (tsconfigPath) {
this.project = kit.createTypeScriptKitProject(languages, env, tsconfigPath, [
this.linter = kit.createTypeScriptChecker(languages, services, tsconfigPath, [
{ extension: 'astro', isMixedContent: true, scriptKind: 7 },
{ extension: 'vue', isMixedContent: true, scriptKind: 7 },
{ extension: 'svelte', isMixedContent: true, scriptKind: 7 },
]);
} else {
this.project = kit.createTypeScriptInferredKitProject(languages, env, () => {
this.linter = kit.createTypeScriptInferredChecker(languages, services, () => {
return fg.sync('**/*.astro', {
cwd: this.workspacePath,
ignore: ['node_modules'],
absolute: true,
});
});
}

this.linter = kit.createLinter(services, env, this.project);
}

private getTsconfig() {
Expand Down

0 comments on commit fc3c13c

Please sign in to comment.