Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jan 30, 2026

Fourslash tests failed for .js files when compiler options were provided to the inferred project without explicitly setting AllowJs. The inferred project only applied its AllowJs: true default when compilerOptions == nil, causing .js files to be excluded from the project.

Changes

Fix in internal/project/project.go:

func NewInferredProject(...) {
    if compilerOptions == nil {
        compilerOptions = &core.CompilerOptions{
            AllowJs: core.TSTrue,
            // ... other defaults
        }
    } else {
        // Apply defaults for unset options
        if compilerOptions.AllowJs == core.TSUnknown {
            compilerOptions.AllowJs = core.TSTrue
        }
    }
    // ...
}

Now applies AllowJs: true default when the option is unset (TSUnknown), regardless of whether compilerOptions is nil.

Test coverage in internal/fourslash/tests/test_js_file_issue_test.go:

  • .js files with no JS-related compiler options (reproduces bug, verifies fix)
  • .js files with @checkJs: true (ensures existing behavior preserved)
  • .js files with explicit @allowJs: false (ensures explicit settings override defaults)
Original prompt

This section details on the original issue you should resolve

<issue_title>Fourslash is broken when making requests in unconfigured .js files</issue_title>
<issue_description>Error message:

--- FAIL: TestAutoImportCompletionJs (0.07s)
    c:/typescript-go/internal/fourslash/tests/autoImportCompletion_test.go:159: At marker 'd': textDocument/completion request returned error: [-32603]: no project found for URI file:///d.js
FAIL
FAIL	github.com/microsoft/typescript-go/internal/fourslash/tests	1.758s

Repro:

Fails on requests called in .js files (formatting, completions, codefixes, etc)

Example: in internal/fourslash/tests/autoImportCompletions_test.go:

func TestAutoImportCompletionJs(t *testing.T) {
	t.Parallel()
	defer testutil.RecoverAndFail(t, "Panic on fourslash test")
	const content = `// @Filename: a.js
export const someVar = 10;

// @Filename: d.js
import {someVar} from "./a";
someVar;
a/*d*/
`
	f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content)
	defer done()
		f.VerifyCompletions(t, "d", &fourslash.CompletionsExpectedList{
		UserPreferences: &lsutil.UserPreferences{
			IncludeCompletionsForModuleExports:    core.TSTrue,
			IncludeCompletionsForImportStatements: core.TSTrue,
		},
		IsIncomplete: false,
		ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{
			CommitCharacters: &DefaultCommitCharacters,
			EditRange:        Ignored,
		},
		Items: &fourslash.CompletionsExpectedItems{
			Includes: []fourslash.CompletionsExpectedItem{"someVar", "anotherVar"},
		},
	})
}

Info:

I've traced it back to .js files not being found in a project during GetDefaultProject</issue_description>

Comments on the Issue (you are @copilot in this section)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Issue: Fourslash tests were failing when making requests to .js files
without explicit @allowJs or @checkjs compiler options.

Root cause: The NewInferredProject function was not applying the
default AllowJs: true setting when compiler options were explicitly
provided (even if AllowJs was not set).

Solution: Apply the AllowJs default when compilerOptions is non-nil
but AllowJs is TSUnknown. This ensures JavaScript files are always
supported in the inferred project, which matches the intended behavior
and TypeScript's language server.

Test: Added test_js_file_issue_test.go with two tests demonstrating
the issue and verifying the fix.
Copilot AI changed the title [WIP] Fix Fourslash error for requests in unconfigured .js files Fix inferred project JavaScript file support when compiler options are provided Jan 30, 2026
Copilot AI requested a review from iisaduan January 30, 2026 21:58
Comment on lines +124 to +128
} else {
// Apply inferred project defaults for options that are not explicitly set
if compilerOptions.AllowJs == core.TSUnknown {
compilerOptions.AllowJs = core.TSTrue
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems vaguely right given InferredProject has:

    override setCompilerOptions(options?: CompilerOptions): void {
        // Avoid manipulating the given options directly
        if (!options && !this.getCompilationSettings()) {
            return;
        }
        const newOptions = cloneCompilerOptions(options || this.getCompilationSettings());
        if (this._isJsInferredProject && typeof newOptions.maxNodeModuleJsDepth !== "number") {
            newOptions.maxNodeModuleJsDepth = 2;
        }
        else if (!this._isJsInferredProject) {
            newOptions.maxNodeModuleJsDepth = undefined;
        }
        newOptions.allowJs = true;
        super.setCompilerOptions(newOptions);
    }

But, mutating the input seems suspect

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fourslash is broken when making requests in unconfigured .js files

3 participants