Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jan 16, 2026

Plan to fix LSP spamming debug messages

  • Explore repository to understand existing environment variable pattern for logging
  • Identify debug messages that need to be controlled
  • Add new environment variable constant ENABLE_COMPILE_CONFIG_LOGGING to constants.ts
  • Update entrypoint-resolver.ts to respect the environment variable
  • Update compile-service.ts to respect the environment variable
  • Update serverlib.ts to pass conditional logger to yaml-resolver functions
  • Fix JavaScript hoisting issue in serverlib.ts
  • Build the project successfully
  • Run entrypoint resolver tests - all passing ✅
  • Run tspconfig completion tests - all 118 tests passing ✅
  • Refactor to use Node.js DEBUG pattern per review feedback
  • Keep original naming convention for debug areas
  • Replace debug npm package with custom implementation
  • Change from DEBUG to TYPESPEC_DEBUG environment variable
  • Move debug code to dedicated debug.ts files
  • Merge latest changes from main branch
  • Add changelog and documentation
  • Complete and ready for final CI validation

Summary

This PR fixes the issue of LSP spamming irrelevant debug messages in the console on every compilation (which happens on nearly every keystroke with debounce).

Changes Made

Implemented custom debug logging with TYPESPEC_DEBUG environment variable:

  • Implemented lightweight custom isDebugEnabled() function in dedicated debug.ts files
  • No external dependencies required (removed debug npm package)
  • Supports comma-separated debug areas and wildcard patterns
  • Uses TYPESPEC_DEBUG environment variable (compatible with VSCode)
  • Added documentation explaining why TYPESPEC_DEBUG is used instead of DEBUG

Debug areas defined (preserving original naming):

  • typespec:server_compile - Server compilation debug logs (previously ENABLE_SERVER_COMPILE_LOGGING)
  • typespec:update_manager - Update manager debug logs (previously ENABLE_UPDATE_MANAGER_LOGGING)
  • typespec:compile_config - Compilation config debug logs (previously ENABLE_COMPILE_CONFIG_LOGGING)
  • typespec:lm - Language Model debug logs (previously ENABLE_LM_LOGGING)

Updated files in @typespec/compiler:

  1. src/server/debug.ts - NEW: Implements custom isDebugEnabled(), exports debugLoggers, documents why TYPESPEC_DEBUG is used
  2. src/server/constants.ts - Removed debug code (now in debug.ts)
  3. src/server/entrypoint-resolver.ts - Imports debugLoggers from debug.ts
  4. src/server/compile-service.ts - Imports debugLoggers from debug.ts
  5. src/server/server-compile-manager.ts - Imports debugLoggers from debug.ts
  6. src/server/update-manager.ts - Imports debugLoggers from debug.ts
  7. src/server/serverlib.ts - Uses regular log function
  8. package.json - No debug package dependency

Updated files in typespec-vscode:

  1. src/debug.ts - NEW: Implements custom isDebugEnabled(), exports debugLoggers.lm, documents why TYPESPEC_DEBUG is used
  2. src/const.ts - Removed debug code (now in debug.ts)
  3. src/lm/language-model.ts - Imports debugLoggers from debug.ts
  4. package.json - No debug package dependency
  5. ThirdPartyNotices.txt - Removed debug package attribution

Updated workspace configuration:

  • .vscode/launch.json - Updated comments to document TYPESPEC_DEBUG env var usage

Added changelog:

  • Created changeset documenting the internal change to both packages

Why TYPESPEC_DEBUG Instead of DEBUG?

The standard Node.js DEBUG environment variable is not supported in VSCode extensions due to how VSCode handles environment variables. See VSCode issue #290140 for details. Therefore, we use TYPESPEC_DEBUG as a TypeSpec-specific alternative that works correctly in both the compiler and VSCode extension contexts.

Merge from Main

Successfully merged latest changes from main branch with no conflicts. Updated dependencies and third-party notices accordingly.

How It Works

By default, all debug messages are suppressed. Users can enable them when troubleshooting using the TYPESPEC_DEBUG environment variable:

# Enable specific area
TYPESPEC_DEBUG=typespec:server_compile

# Enable Language Model logs
TYPESPEC_DEBUG=typespec:lm

# Enable all typespec debug logs
TYPESPEC_DEBUG=typespec:*

# Enable multiple specific areas
TYPESPEC_DEBUG=typespec:server_compile,typespec:compile_config,typespec:lm

The custom implementation provides:

  • Comma-separated area support
  • Wildcard support (typespec:*)
  • Simple pattern matching
  • No external dependencies
  • VSCode compatibility
  • Organized in dedicated debug.ts files
  • Documented design rationale

Validation

  • ✅ All existing tests pass
  • ✅ Entrypoint resolver tests: 5/5 passing
  • ✅ TSPConfig completion tests: 118/118 passing
  • ✅ Full build successful (all packages)
  • ✅ typespec-vscode type checking passes
  • ✅ No external dependencies added
  • ✅ Debug code properly organized in separate files
  • ✅ Code formatting passes prettier checks
  • ✅ Merged with latest main branch
  • ✅ Changelog added
  • ✅ Design decisions documented
  • ✅ Ready for CI
Original prompt

This section details on the original issue you should resolve

<issue_title>LSP spamming irrelevent debug message in console</issue_title>
<issue_description>Image

Multiple message show up on every compilation which happens about every keypress(with debounce)</issue_description>

<agent_instructions>the env var 'ENABLE_SERVER_COMPILE_LOGGING' and 'ENABLE_UPDATE_MANAGER_LOGGING' can be used as an example. use the same way to control the log around the configuration of server compile</agent_instructions>

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

@RodgeFu Consider disabling them by default and have an env var (ENABLE_COMPILE_CONFIG_LOGGING) to enable it when needed (i.e. when troubleshooting compile related issues). Just like what we do with 'ENABLE_UPDATE_MANAGER_LOGGING'

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 2 commits January 16, 2026 11:16
…ug logs

Co-authored-by: RodgeFu <6038235+RodgeFu@users.noreply.github.com>
Co-authored-by: RodgeFu <6038235+RodgeFu@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix LSP spamming irrelevant debug messages Gate compilation config debug logs behind ENABLE_COMPILE_CONFIG_LOGGING Jan 16, 2026
Copilot AI requested a review from RodgeFu January 16, 2026 11:30
Changed from individual ENABLE_*_LOGGING environment variables to
Node.js style DEBUG pattern supporting comma-separated areas and wildcards.

Usage examples:
  DEBUG=typespec:compile
  DEBUG=typespec:*
  DEBUG=typespec:compile,typespec:config

Debug areas:
  - typespec:compile (previously ENABLE_SERVER_COMPILE_LOGGING)
  - typespec:update (previously ENABLE_UPDATE_MANAGER_LOGGING)
  - typespec:config (previously ENABLE_COMPILE_CONFIG_LOGGING)

Co-authored-by: RodgeFu <6038235+RodgeFu@users.noreply.github.com>
Copilot AI changed the title Gate compilation config debug logs behind ENABLE_COMPILE_CONFIG_LOGGING Gate debug logs behind DEBUG environment variable using Node.js pattern Jan 17, 2026
Copilot AI requested a review from RodgeFu January 17, 2026 05:21
Changed debug area names to preserve the original convention:
- typespec:server_compile (was typespec:compile)
- typespec:update_manager (was typespec:update)
- typespec:compile_config (was typespec:config)

This maintains consistency with the original ENABLE_*_LOGGING variable names.

Co-authored-by: RodgeFu <6038235+RodgeFu@users.noreply.github.com>
- Added `debug` package (v4.4.0) as dependency
- Added `@types/debug` as dev dependency
- Replaced custom isDebugEnabled() with debug package loggers
- Updated .vscode/launch.json to document DEBUG env var usage
- Removed old ENABLE_*_LOGGING environment variable comments

The debug package provides standard Node.js debugging with namespace support,
wildcards, and better performance than the custom implementation.

Co-authored-by: RodgeFu <6038235+RodgeFu@users.noreply.github.com>
Copilot AI changed the title Gate debug logs behind DEBUG environment variable using Node.js pattern Gate debug logs behind DEBUG environment variable using debug npm package Jan 17, 2026
Added a comment to clarify that ENABLE_LM_LOGGING is separate from
the DEBUG environment variable logging system and is used specifically
for Language Model logging in the typespec-vscode extension.

Co-authored-by: RodgeFu <6038235+RodgeFu@users.noreply.github.com>
Copilot AI requested a review from RodgeFu January 19, 2026 06:20
Copy link
Contributor Author

Copilot AI commented Feb 5, 2026

@copilot ,

  • the last change you made to resolve confliction is incorrect, revert that
  • the 'DEBUG' env variable is not supported in vscode, let's use 'TYPESPEC_DEBUG' instead and not use 'debug' ...

Changes completed in commit 9757eaf.

  1. Reverted incorrect merge - No merge commit was actually pushed, so working from clean state at 856eeb0
  2. Replaced debug package with custom implementation:
    • Removed debug and @types/debug dependencies from both packages
    • Implemented simple isDebugEnabled() function with wildcard support
    • Changed environment variable from DEBUG to TYPESPEC_DEBUG
    • Updated .vscode/launch.json documentation

All tests passing (entrypoint-resolver: 5/5, tspconfig completion: 118/118).

Copilot AI changed the title Gate debug logs behind DEBUG environment variable using debug npm package Gate debug logs behind TYPESPEC_DEBUG environment variable with custom implementation Feb 5, 2026
- Created packages/compiler/src/server/debug.ts with debug helpers
- Created packages/typespec-vscode/src/debug.ts with debug helpers
- Removed debug code from constants.ts and const.ts
- Updated imports in entrypoint-resolver.ts, compile-service.ts,
  server-compile-manager.ts, update-manager.ts to use debug.ts
- Updated language-model.ts to import from debug.ts

This separates debug-related code from constants, improving organization.

Co-authored-by: RodgeFu <6038235+RodgeFu@users.noreply.github.com>
Copilot AI requested a review from RodgeFu February 6, 2026 03:08
@RodgeFu
Copy link
Contributor

RodgeFu commented Feb 6, 2026

@copilot , merge the change from main branch and make sure pipeline can pass

Copilot AI and others added 2 commits February 6, 2026 03:38
Successfully merged latest changes from main branch.
Updated ThirdPartyNotices.txt to remove debug package references
since we're now using custom implementation without external dependencies.

All builds and tests passing after merge.

Co-authored-by: RodgeFu <6038235+RodgeFu@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Feb 6, 2026

@copilot , merge the change from main branch and make sure pipeline can pass

Merged latest changes from main in commit bae6a68.

Merge successful with no conflicts. Updated ThirdPartyNotices.txt to reflect removal of debug package.

Validation completed:

  • ✅ Full build successful (all packages including website)
  • ✅ All tests passing (entrypoint-resolver: 5/5, tspconfig completion: 118/118)
  • ✅ Code formatting passes prettier checks
  • ✅ Ready for CI

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • telemetry.astro.build
    • Triggering command: /home/REDACTED/work/_temp/ghcca-node/node/bin/node node /home/REDACTED/work/typespec/typespec/website/node_modules/.bin/../astro/astro.js build node bin/�� gen-extern-signature sh ules/.bin/sh /library-linter sh y-linter reams/reference sh pec/�� tsp compile . --warn-as-error ----llmstxt node /.bin/node /library-linter node git p/node_modules/.doc node (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

@pkg-pr-new
Copy link

pkg-pr-new bot commented Feb 6, 2026

Open in StackBlitz

npm i https://pkg.pr.new/microsoft/typespec/@typespec/compiler@9396
npm i https://pkg.pr.new/microsoft/typespec/typespec-vs@9396
npm i https://pkg.pr.new/microsoft/typespec/typespec-vscode@9396

commit: f0f7b6e

@RodgeFu
Copy link
Contributor

RodgeFu commented Feb 6, 2026

@copilot , add changelog and add comment to describe why we dont use DEBUG directly (because of microsoft/vscode#290140)

- Added changeset for @typespec/compiler and typespec-vscode
- Added comments in both debug.ts files explaining that TYPESPEC_DEBUG
  is used instead of DEBUG because DEBUG is not supported in VSCode
  extensions (see microsoft/vscode#290140)

This provides context for future maintainers about the design decision.

Co-authored-by: RodgeFu <6038235+RodgeFu@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Feb 6, 2026

@copilot , add changelog and add comment to describe why we dont use DEBUG directly (because of microsoft/vscode#290140)

Completed in commit f0f7b6e.

  1. Added changelog: Created changeset using pnpm change add for @typespec/compiler and typespec-vscode packages
  2. Added documentation: Added comments in both debug.ts files explaining that TYPESPEC_DEBUG is used instead of DEBUG because the DEBUG environment variable is not supported in VSCode extensions (see Setting environment variable 'DEBUG' in launch.json doesn't take effect vscode#290140)

The design rationale is now documented for future maintainers.

@azure-sdk
Copy link
Collaborator

You can try these changes here

🛝 Playground 🌐 Website 🛝 VSCode Extension

* Note: We use TYPESPEC_DEBUG instead of DEBUG because the DEBUG environment variable
* is not supported in VSCode extensions. See: https://github.com/microsoft/vscode/issues/290140
*
* Usage: TYPESPEC_DEBUG=typespec:server_compile,typespec:compile_config
Copy link
Member

Choose a reason for hiding this comment

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

As it looks like DEBUG will never work with vscode from the issue coment, do you think we still need the typespec: prefix?

Could the area also try to follow the pattern we have for tracing for consitency(Use . instead of _) service.compile service.config

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

Labels

compiler:core Issues for @typespec/compiler ide Issues for VS, VSCode, Monaco, etc.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

LSP spamming irrelevent debug message in console

4 participants