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

Extension development: support to show functions in console.log #16450

Closed
Jakobud opened this issue Dec 4, 2016 · 7 comments
Closed

Extension development: support to show functions in console.log #16450

Jakobud opened this issue Dec 4, 2016 · 7 comments
Assignees
Labels
debug Debug viewlet, configurations, breakpoints, adapter issues feature-request Request for new features or functionality *out-of-scope Posted issue is not in scope of VS Code

Comments

@Jakobud
Copy link

Jakobud commented Dec 4, 2016

  • VSCode Version: 1.7.2
  • OS Version: Win7 x64

I have the following basic object:

// test.js
module.exports = {
  hello: 'world',
  callback: () => {
    console.log('test!');
  }
}

Using Node.js normally I can easily require this object and utilize it:

const test = require('./test');
console.log(test);

As expected, yields:

{ hello: 'world', callback: [Function: callback] }

However, when I am developing a VSCode extension, if I require this same exact file:

const vscode = require('vscode');
const test = require('./test');

let activate = (context) => {
  let disposable = vscode.commands.registerCommand('myExtension.myCommand', () => {
    console.log(test);
  });
  context.subscriptions.push(disposable);
}
exports.activate = activate;
let deactivate = () => { }
exports.deactivate = deactivate;

I get this:

{ hello: "world" }

The function that I specified in the exported object is completely ignored when it's required into the extension. I've never come across this with normal Node.js development. Can anyone shed some light on this? Is there something obvious I'm doing wrong that I'm just missing?

@Jakobud
Copy link
Author

Jakobud commented Dec 4, 2016

As I'm looking deeper into this, I'm finding 2 things:

  1. This doesn't apply only to requiring external objects, but if I define the object itself in extension.js, I get the same result.

  2. The functions are still there and are accessible in your code. They just don't show up when using console.log for some reason.

@chrmarti chrmarti changed the title Extension development: Required CommonJS module function in object is ignored Extension development: console.log does't show functions Dec 5, 2016
@chrmarti chrmarti assigned jrieken and bpasero and unassigned jrieken Dec 5, 2016
@Jakobud
Copy link
Author

Jakobud commented Dec 5, 2016

More details, looks like console.log(Object.keys(test)); does return an array with the appropriate keys in it.

@bpasero bpasero changed the title Extension development: console.log does't show functions Extension development: support to show functions in console.log Dec 5, 2016
@bpasero bpasero added feature-request Request for new features or functionality debug Debug viewlet, configurations, breakpoints, adapter issues labels Dec 5, 2016
@bpasero
Copy link
Member

bpasero commented Dec 5, 2016

This is a result of us using JSON serialisation to convert objects being outputted to output in the debug console. One workaround would be to just do Function.toString() and show the value as string, but people might confuse that with an actual string because we cannot know when deserialising that the thing was a function after all.

I think the way forward here is to get rid of JSON at all and support real objects from extension debug to the repl.

@weinand @isidorn do we already have an item for this to support it for extension development? Similar to #15796

@isidorn
Copy link
Contributor

isidorn commented Dec 5, 2016

@bpasero we do not have an item for this already, but @weinand would know better

@bpasero bpasero removed their assignment Dec 5, 2016
@jrieken
Copy link
Member

jrieken commented Dec 5, 2016

This needs a replacer-function when calling JSON.stringify

@weinand weinand self-assigned this Dec 5, 2016
@Jakobud
Copy link
Author

Jakobud commented Dec 5, 2016

Thank you for the clarification guys. Not really a huge deal breaking priority bug (I don't think?) but I just wanted to make sure I got it submitted.

@weinand weinand added the *out-of-scope Posted issue is not in scope of VS Code label Sep 11, 2018
@vscodebot
Copy link

vscodebot bot commented Sep 11, 2018

This issue is being closed to keep the number of issues in our inbox on a manageable level, we are closing issues that are not going to be addressed in the foreseeable future: We look at the number of votes the issue has received and the number of duplicate issues filed. If you disagree and feel that this issue is crucial: We are happy to listen and to reconsider.

If you wonder what we are up to, please see our roadmap and issue reporting guidelines.

Thanks for your understanding and happy coding!

@vscodebot vscodebot bot closed this as completed Sep 11, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
debug Debug viewlet, configurations, breakpoints, adapter issues feature-request Request for new features or functionality *out-of-scope Posted issue is not in scope of VS Code
Projects
None yet
Development

No branches or pull requests

5 participants