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

feat(tsconfig): json5 to parse tsconfig #157

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 5 additions & 0 deletions .changeset/little-chairs-provide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"react-ts-css": minor
---

feat(tsconfig): json5 to parse tsconfig
10 changes: 10 additions & 0 deletions examples/react-app/src/test/aliased-modules/AliasedModules.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import styles from "@d/DuplicateSelectors.module.scss";
import buttonCss from "@s/button.module.scss";

export default function () {
return (
<div className={styles.flex}>
<p className={buttonCss["btn-secondary"]}></p>
</div>
);
}
18 changes: 8 additions & 10 deletions examples/react-app/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@
"compilerOptions": {
"target": "ESNext",
"useDefineForClassFields": true,
"lib": [
"DOM",
"DOM.Iterable",
"ESNext"
],
"lib": ["DOM", "DOM.Iterable", "ESNext"],
"allowJs": false,
"skipLibCheck": true,
"esModuleInterop": false,
Expand All @@ -19,14 +15,16 @@
"isolatedModules": true,
"noEmit": true,
"jsx": "react-jsx",
"baseUrl": "src"
"baseUrl": "src",
"paths": {
"@d": ["./test/DuplicateSelectors/*"],
"@s": ["./styles/*"]
}
},
"include": [
"src"
],
"include": ["src"],
"references": [
{
"path": "./tsconfig.node.json"
}
]
}
}
39 changes: 29 additions & 10 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 9 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
"theme": "dark"
},
"engines": {
"vscode": "^1.72.0"
"vscode": "^1.90.0"
},
"categories": [
"Programming Languages"
Expand Down Expand Up @@ -180,33 +180,34 @@
"yarn": false
},
"devDependencies": {
"@babel/parser": "^7.19.3",
"@babel/traverse": "^7.19.3",
"@babel/types": "^7.19.3",
"@changesets/cli": "^2.27.1",
"@types/babel__traverse": "^7.18.2",
"@types/glob": "^7.2.0",
"@types/mocha": "^9.1.1",
"@types/node": "^16.18.11",
"@types/sinon": "^10.0.13",
"@types/vscode": "^1.72.0",
"@types/vscode": "^1.90.0",
"@typescript-eslint/eslint-plugin": "^5.31.0",
"@typescript-eslint/parser": "^5.31.0",
"@vscode/test-electron": "^2.3.8",
"@vscode/vsce": "^2.16.0",
"closest-match": "^1.3.3",
"eslint": "^8.20.0",
"fast-glob": "^3.2.12",
"glob": "^8.0.3",
"json5": "^2.2.3",
"mocha": "^10.0.0",
"ovsx": "^0.8.3",
"sinon": "^14.0.1",
"ts-loader": "^9.3.1",
"typescript": "^4.9.4",
"vsce": "^2.11.0",
"webpack": "^5.74.0",
"webpack-cli": "^4.10.0",
"vscode-css-languageservice": "^6.2.12",
"@babel/parser": "^7.19.3",
"@babel/traverse": "^7.19.3",
"closest-match": "^1.3.3",
"fast-glob": "^3.2.12"
"webpack": "^5.74.0",
"webpack-cli": "^4.10.0"
},
"dependencies": {
"typescript-cleanup-definitions": "^1.1.0"
Expand Down
16 changes: 10 additions & 6 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,6 @@ workspace.onDidCreateFiles((e) => {
Store.addSourceFiles(e.files);
});

workspace.onDidChangeTextDocument((e) => {
Store.bootstrap();
});

window.onDidChangeActiveTextEditor((e) => {
Store.bootstrap();
});
Expand All @@ -87,6 +83,13 @@ const syncWithGit = () => {
};

export async function activate(context: ExtensionContext): Promise<void> {
workspace.onDidChangeTextDocument((e) => {
// Event is fired when logging to output channel
if (e.document.fileName.includes(context.extension.id)) return;

Store.bootstrap();
});

workspace.onDidChangeConfiguration(async (e) => {
const affected = e.affectsConfiguration(EXT_NAME);
if (affected) {
Expand All @@ -105,6 +108,7 @@ export async function activate(context: ExtensionContext): Promise<void> {
await syncTsPlugin();
}
});

const syncTsPlugin = async () => {
const ext = extensions.getExtension("vscode.typescript-language-features");
if (ext) {
Expand Down Expand Up @@ -188,9 +192,9 @@ export async function activate(context: ExtensionContext): Promise<void> {
context.subscriptions.push(_cssCodeLensProvider);
context.subscriptions.push(_cssRenameSelectorProvider);
} catch (e) {
console.error(e);
Store.outputChannel.error((e as Error).message);
window.showWarningMessage(
"Something went wrong while activating React-TS-CSS extension"
"Something went wrong while activating React-TS-CSS extension. Check the output channel"
);
}
}
Expand Down
5 changes: 4 additions & 1 deletion src/parser/v2/css.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import {
isSibling,
isSuffix,
} from "../utils";
import Store from "../../store/Store";

export const getLanguageService = (module: string) => {
switch (path.extname(module) as CssModuleExtensions) {
Expand Down Expand Up @@ -86,7 +87,9 @@ export const parseCss = async (
);
return { selectors, eofRange, variables, ast: ast as Stylesheet, colors };
} catch (e) {
console.error(e);
Store.outputChannel.error(
`CSSParserError: Parsing css module ${module} failed`
);
}
};

Expand Down
11 changes: 10 additions & 1 deletion src/providers/css/CSSProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,13 @@ export class CSSProvider {
})
);
} catch (e) {
console.error(e);
Store.outputChannel.error(
`CSSProviderError: Failed in document '${
this.document.uri.fsPath
}' at '${this.position.line}:${this.position.character}'
Provider: ${this.providerKind}
${e as Error}`
);
}

return candidates;
Expand Down Expand Up @@ -529,6 +535,9 @@ export class CSSDiagnosticsProvider extends CSSProvider {
const references = await this.getReferences();
const filePath = normalizePath(this.document.uri.fsPath);
const source_css_file = Store.cssModules.get(filePath);
if (!source_css_file) {
return [];
}
const selectors = (await parseCss(source_css_file ?? ""))?.selectors;
if (!selectors) return [];

Expand Down
5 changes: 3 additions & 2 deletions src/providers/css/codelens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import * as vscode from "vscode";
import Settings from "../../settings";
import { ProviderKind } from "../types";
import { CSSCodeLensProvider, CSSProvider } from "./CSSProvider";
import Store from "../../store/Store";

export class ReferenceCodeLens extends vscode.CodeLens {
constructor(
Expand Down Expand Up @@ -29,8 +30,8 @@ export class ReferenceCodeLensProvider implements vscode.CodeLensProvider {
});

return provider.provideCodeLenses();
} catch (e) {
console.error(e);
} catch (e: any) {
Store.outputChannel.error(`ReferenceCodeLensProviderError: ${e.message}`);
return [];
}
}
Expand Down
8 changes: 6 additions & 2 deletions src/providers/css/rename-selector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import Settings from "../../settings";
import { CSSProvider, CSSRenameProvider } from "./CSSProvider";
import { ProviderKind } from "../types";
import { isSuffix, stripSelectHelpers } from "../../parser/utils";
import Store from "../../store/Store";
export class RenameSelectorProvider implements RenameProvider {
async provideRenameEdits(
document: TextDocument,
Expand Down Expand Up @@ -55,8 +56,11 @@ export class RenameSelectorProvider implements RenameProvider {
});
const range = await provider.getSelectorRange();
return range;
} catch (e) {
console.error(e);
} catch (e: any) {
Store.outputChannel.error(
`RenameSelectorProviderError: Failed in document '${document}' at '${position.line}:${position.character}'
${e.message}`
);
return;
}
}
Expand Down
5 changes: 4 additions & 1 deletion src/providers/ts/code-actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,10 @@ export class DiagnosticCodeAction implements vscode.CodeActionProvider {
action.diagnostics = [diagnostic];
return action;
} catch (e) {
console.log(e);
Store.outputChannel.error(
e as Error,
`CodeActionError: Ingore warning failed`
);
throw e;
}
}
Expand Down
13 changes: 10 additions & 3 deletions src/providers/ts/completion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
import Settings from "../../settings";
import { ProviderKind } from "../types";
import { TSProvider } from "./TSProvider";
import Store from "../../store/Store";

export class SelectorsCompletionProvider implements CompletionItemProvider {
async provideCompletionItems(
Expand Down Expand Up @@ -89,7 +90,10 @@ export class SelectorsCompletionProvider implements CompletionItemProvider {
}
} catch (e) {}
} catch (e) {
console.info(e);
Store.outputChannel.error(
`${e as Error}`,
`SelectorCompletionProvider: Failed in document '${document}' at '${position.line}:${position.character}'`
);
}
return [];
}
Expand All @@ -115,8 +119,11 @@ export class ImportCompletionProvider implements CompletionItemProvider {
additionalTextEdits: c.additionalEdits,
}))
);
} catch (e) {
console.error(e);
} catch (e: any) {
Store.outputChannel.error(
`ImportCompletionProvider: Failed in document '${document}' at '${position.line}:${position.character}'
${e.message}`
);
return;
}
}
Expand Down
Loading
Loading