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

[Not Ready] [typespec-vscode] Improvements for the intellisense of tspconfig.yaml #5186

Open
wants to merge 26 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
b0ac596
Merge pull request #1 from microsoft/main
mzhongl524 Nov 22, 2024
3fcbe52
Merge branch 'microsoft:main' into main
mzhongl524 Nov 25, 2024
881e4b6
Add a intellisense for the extends path in tspconfig.yaml
mzhongl524 Nov 25, 2024
dd4314b
fix warning
mzhongl524 Nov 25, 2024
a43f7e9
Some autocompletes in linters, extends autocomplete updates
mzhongl524 Nov 26, 2024
47e65f8
fix emitter option auto complete while inside "" will add extra ""
mzhongl524 Nov 27, 2024
18025cc
fix emitter option auto complete debug; revert vscode side code
mzhongl524 Nov 28, 2024
51084bc
linter complete rule
mzhongl524 Dec 2, 2024
7344ef2
extends autocomplete
mzhongl524 Dec 2, 2024
82f2ac7
imports autocomplete
mzhongl524 Dec 2, 2024
81df10c
add more info to distinguish required or optional parameter for emitt…
mzhongl524 Dec 3, 2024
da93740
completion for known variables/parameters/env interpolation
mzhongl524 Dec 4, 2024
54726b8
update extends/imports path autocompletion and required or optional p…
mzhongl524 Dec 5, 2024
759ec59
update linter rules/ruleSets
mzhongl524 Dec 5, 2024
6f249c7
Partially updated
mzhongl524 Dec 9, 2024
849973b
Update variable interpolation
mzhongl524 Dec 9, 2024
9d30083
updated
mzhongl524 Dec 11, 2024
3780210
updated and add test
mzhongl524 Dec 16, 2024
bfb5b14
updated
mzhongl524 Dec 17, 2024
92a2540
updated and add some testing
mzhongl524 Dec 19, 2024
5b8eba7
Create improvements-for-the-intellisense-of-tspconfig.yaml-2024-11-19…
mzhongl524 Dec 19, 2024
facf5e5
update code and change logs
mzhongl524 Dec 23, 2024
3bf6351
Update improvements-for-the-intellisense-of-tspconfig.yaml-2024-11-19…
mzhongl524 Dec 24, 2024
26e1f3e
updated
mzhongl524 Dec 24, 2024
73eea1f
Merge branch 'improvements-for-the-intellisense-of-tspconfig.yaml' of…
mzhongl524 Dec 24, 2024
81c3ced
updated
mzhongl524 Dec 24, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,56 +1,70 @@
import { joinPaths } from "../core/path-utils.js";
import { NpmPackage, NpmPackageProvider } from "./npm-package-provider.js";

export class EmitterProvider {
export class LibraryProvider {
private isEmitterPackageCache = new Map<string, boolean>();
private isLinterPackageCache = new Map<string, boolean>();
mzhongl524 marked this conversation as resolved.
Show resolved Hide resolved
private isGetEmitter: boolean = false;
constructor(private npmPackageProvider: NpmPackageProvider) {}

/**
* Set whether to get the emitter library or the linter library
* @param isGetEmitter true if you want to get the emitter library, false if you want to get the linter library
*/
setIsGetEmitterVal(isGetEmitter: boolean): void {
this.isGetEmitter = isGetEmitter;
}

/**
*
* @param startFolder folder starts to search for package.json with emitters defined as dependencies
* @param startFolder folder starts to search for package.json with emitters/linters defined as dependencies
mzhongl524 marked this conversation as resolved.
Show resolved Hide resolved
* @returns
*/
async listEmitters(startFolder: string): Promise<Record<string, NpmPackage>> {
async listLibraries(startFolder: string): Promise<Record<string, NpmPackage>> {
const packageJsonFolder = await this.npmPackageProvider.getPackageJsonFolder(startFolder);
if (!packageJsonFolder) return {};

const pkg = await this.npmPackageProvider.get(packageJsonFolder);
const data = await pkg?.getPackageJsonData();
if (!data) return {};

const emitters: Record<string, NpmPackage> = {};
const libs: Record<string, NpmPackage> = {};
const allDep = {
...(data.dependencies ?? {}),
...(data.devDependencies ?? {}),
};
for (const dep of Object.keys(allDep)) {
const depPkg = await this.getEmitterFromDep(packageJsonFolder, dep);
const depPkg = await this.getLibraryFromDep(packageJsonFolder, dep);
if (depPkg) {
emitters[dep] = depPkg;
libs[dep] = depPkg;
}
}
return emitters;
return libs;
}

/**
*
* @param startFolder folder starts to search for package.json with emitters defined as dependencies
* @param startFolder folder starts to search for package.json with emitters/linter defined as dependencies
* @param emitterName
* @returns
*/
async getEmitter(startFolder: string, emitterName: string): Promise<NpmPackage | undefined> {
async getLibrary(startFolder: string, emitterName: string): Promise<NpmPackage | undefined> {
const packageJsonFolder = await this.npmPackageProvider.getPackageJsonFolder(startFolder);
if (!packageJsonFolder) {
return undefined;
}
return this.getEmitterFromDep(packageJsonFolder, emitterName);
return this.getLibraryFromDep(packageJsonFolder, emitterName);
}

private async isEmitter(depName: string, pkg: NpmPackage) {
if (this.isEmitterPackageCache.has(depName)) {
if (this.isGetEmitter && this.isEmitterPackageCache.has(depName)) {
return this.isEmitterPackageCache.get(depName);
}

if (!this.isGetEmitter && this.isLinterPackageCache.has(depName)) {
return this.isLinterPackageCache.get(depName);
}

const data = await pkg.getPackageJsonData();
// don't add to cache when failing to load package.json which is unexpected
if (!data) return false;
Expand All @@ -61,16 +75,27 @@ export class EmitterProvider {
const exports = await pkg.getModuleExports();
// don't add to cache when failing to load exports which is unexpected
if (!exports) return false;
const isEmitter = exports.$onEmit !== undefined;
this.isEmitterPackageCache.set(depName, isEmitter);
const isEmitter = this.isGetEmitter
? exports.$onEmit !== undefined
: exports.$linter !== undefined;
if (this.isGetEmitter) {
this.isEmitterPackageCache.set(depName, isEmitter);
} else {
this.isLinterPackageCache.set(depName, isEmitter);
}
return isEmitter;
} else {
this.isEmitterPackageCache.set(depName, false);
if (this.isGetEmitter) {
this.isEmitterPackageCache.set(depName, false);
} else {
this.isLinterPackageCache.set(depName, false);
}

return false;
}
}

private async getEmitterFromDep(packageJsonFolder: string, depName: string) {
private async getLibraryFromDep(packageJsonFolder: string, depName: string) {
const depFolder = joinPaths(packageJsonFolder, "node_modules", depName);
const depPkg = await this.npmPackageProvider.get(depFolder);
if (depPkg && (await this.isEmitter(depName, depPkg))) {
Expand Down
6 changes: 3 additions & 3 deletions packages/compiler/src/server/serverlib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,9 @@ import { createCompileService } from "./compile-service.js";
import { resolveCompletion } from "./completion.js";
import { Commands } from "./constants.js";
import { convertDiagnosticToLsp } from "./diagnostics.js";
import { EmitterProvider } from "./emitter-provider.js";
import { createFileService } from "./file-service.js";
import { createFileSystemCache } from "./file-system-cache.js";
import { LibraryProvider } from "./lib-provider.js";
import { NpmPackageProvider } from "./npm-package-provider.js";
import { getSymbolStructure } from "./symbol-structure.js";
import { provideTspconfigCompletionItems } from "./tspconfig/completion.js";
Expand Down Expand Up @@ -114,7 +114,7 @@ export function createServer(host: ServerHost): Server {
});
const compilerHost = createCompilerHost();
const npmPackageProvider = new NpmPackageProvider(compilerHost);
const emitterProvider = new EmitterProvider(npmPackageProvider);
const libProvider = new LibraryProvider(npmPackageProvider);
mzhongl524 marked this conversation as resolved.
Show resolved Hide resolved

const compileService = createCompileService({
fileService,
Expand Down Expand Up @@ -703,7 +703,7 @@ export function createServer(host: ServerHost): Server {
if (doc) {
const items = await provideTspconfigCompletionItems(doc, params.position, {
fileService,
emitterProvider,
libProvider: libProvider,
log,
});
return CompletionList.create(items);
Expand Down
Loading
Loading