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

Improve error logging from the Language Service #253

Closed
mizdra opened this issue Dec 8, 2024 · 1 comment
Closed

Improve error logging from the Language Service #253

mizdra opened this issue Dec 8, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@mizdra
Copy link

mizdra commented Dec 8, 2024

Summary

I use Volar.js to implement the TypeScript Language Service Plugin. To do this, I have created an object that satisfies import('@volar/language-core').LanguagePlugin<string>. However, I have written code in the LanguagePlugin.getLanguageId function that causes a runtime error.

I would have expected the error to be contained in the tsserver.log. However, it was not actually contained. This made it difficult to determine why the TypeScript Language Service Plugin was not working.

I would like the error to be contained in tsserver.log for debugging.

Reproduction

repository: https://github.com/mizdra/repro-volar-get-language-id-error

/// <reference types="@volar/typescript" />

const ts = require('typescript/lib/tsserverlibrary');

/**
 * @returns {import('@volar/language-core').LanguagePlugin<string>}
 */
exports.createPngLanguagePlugin = function createPngLanguagePlugin() {
  return {
    getLanguageId(scriptId) {
      throw new Error('something wrong'); // cause a runtime error
      if (scriptId.endsWith('.png')) return 'png';
      return undefined;
    },
    createVirtualCode(scriptId, languageId) {
      if (languageId !== 'png') return undefined;
      const dtsContent = `
declare const I_PNG: { src: string, width: number, height: number };
export default I_PNG;
      `.trim();
      return {
        id: 'main',
        languageId: 'png',
        snapshot: {
          getText: (start, end) => dtsContent.slice(start, end),
          getLength: () => dtsContent.length,
          getChangeRange: () => undefined,
        },
        mappings: [],
      };
    },
    typescript: {
      extraFileExtensions: [
        {
          extension: 'png',
          isMixedContent: true,
          scriptKind: ts.ScriptKind.TS,
        },
      ],
      getServiceScript(root) {
        return {
          code: root,
          extension: ts.Extension.Ts,
          scriptKind: ts.ScriptKind.TS,
        };
      },
    },
  };
}

Expected behavior

tsserver.log contains something wrong.

Actual behavior

tsserver.log does not contain something wrong.

Additional context

Functions such as LanguagePlugin.createVirtualCode, LanguagePlugin.typescript.getServiceScript seem to cause similar problems.

@johnsoncodehk johnsoncodehk added the bug Something isn't working label Dec 8, 2024
@mizdra
Copy link
Author

mizdra commented Dec 15, 2024

I confirmed that the problem has been fixed. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants