Skip to content
Open
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
32 changes: 32 additions & 0 deletions .changeset/wise-walls-rule.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
---
"@effect/language-service": minor
---

Add per-file diagnostic severity overrides in plugin config and inline `--include` / `--exclude` glob filtering for CLI commands.

Example plugin config:

```json
{
"diagnosticSeverity": {
"strictEffectProvide": "warning"
},
"overrides": [
{
"include": ["test/**/*"],
"diagnosticSeverity": {
"strictEffectProvide": "off"
}
}
]
}
```

Example inline CLI filtering:

```bash
effect-language-service diagnostics \
--project tsconfig.json \
--include 'src/**/*' \
--exclude '**/*.test.ts'
```
33 changes: 29 additions & 4 deletions packages/language-service/src/cli/codegen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,13 @@ import * as TypeCheckerUtils from "../core/TypeCheckerUtils"
import * as TypeParser from "../core/TypeParser"
import * as TypeScriptApi from "../core/TypeScriptApi"
import * as TypeScriptUtils from "../core/TypeScriptUtils"
import { applyTextChanges, extractEffectLspOptions, getFileNamesInTsConfig, TypeScriptContext } from "./utils"
import {
applyTextChanges,
extractEffectLspOptions,
filterFilesByPaths,
getFileNamesInTsConfig,
TypeScriptContext
} from "./utils"

export class NoFilesToCodegenError extends Data.TaggedError("NoFilesToCodegenError")<{}> {
get message(): string {
Expand Down Expand Up @@ -46,15 +52,30 @@ const force = Flag.boolean("force").pipe(
Flag.withDescription("Force codegen even if no changes are needed.")
)

const include = Flag.string("include").pipe(
Flag.optional,
Flag.withDescription(
"Optional comma-separated include globs used to filter files after tsconfig discovery. e.g. 'src/**/*,test/**/*'"
)
)

const exclude = Flag.string("exclude").pipe(
Flag.optional,
Flag.withDescription(
"Optional comma-separated exclude globs used to filter files after tsconfig discovery. e.g. '**/*.test.ts,**/*.spec.ts'"
)
)

const BATCH_SIZE = 50

export const codegen = Command.make(
"codegen",
{ file, project, verbose, force },
Effect.fn("codegen")(function*({ file, force, project, verbose }) {
{ file, project, verbose, force, include, exclude },
Effect.fn("codegen")(function*({ exclude, file, force, include, project, verbose }) {
const path = yield* Path.Path
const fs = yield* FileSystem.FileSystem
const tsInstance = yield* TypeScriptContext
const projectRoot = Option.isSome(project) ? path.dirname(project.value) : path.resolve(".")
let filesToCodegen = new Set<string>()
let checkedFilesCount = 0
let updatedFilesCount = 0
Expand All @@ -66,6 +87,7 @@ export const codegen = Command.make(
if (Option.isSome(file)) {
filesToCodegen.add(path.resolve(file.value))
}
filesToCodegen = yield* filterFilesByPaths(filesToCodegen, projectRoot, { include, exclude })
if (filesToCodegen.size === 0) {
return yield* new NoFilesToCodegenError()
}
Expand Down Expand Up @@ -153,7 +175,10 @@ export const codegen = Command.make(
Nano.provideService(TypeScriptApi.TypeScriptApi, tsInstance),
Nano.provideService(
LanguageServicePluginOptions.LanguageServicePluginOptions,
{ ...LanguageServicePluginOptions.parse(pluginConfig), diagnosticsName: false }
{
...LanguageServicePluginOptions.parse(pluginConfig, { projectRoot }),
diagnosticsName: false
}
),
Nano.run,
Result.getOrElse(() => [] as Array<ts.FileTextChanges>)
Expand Down
Loading