1

I have a simple custom library made in node, let's assume:

var extend = require('extend');
var jQuery = require("jquery");

import Logger from './../modules/logger.js';
import Cookie from './../modules/cookie.js';
import DOM from './../modules/dom.js';

export default class MyScript {

    constructor(document, active) {
        this.document = document;
        this.active = active;
        this.$ = jQuery;
    }

    /* utilities */

    /**
     * Tries to convert a string into a number, returns default number if string can't be converted
     * @param  {string} str The string to be converted
     * @param  {number} defaultValue The default number
     * @returns number
     */
    tryParseInt(str, defaultValue) {
        var retValue = defaultValue;
        if (str !== null) {
            if (str.length > 0) {
                if (!isNaN(+str)) {
                    retValue = parseInt(str, 10);
                }
            }
        }
        return retValue;
    }

    /**
     * generates a random string
     * @param  {number} length the length of the string to generate
     * @param  {string} chars the generated string type
     * @returns string
     */
    generateRandomId(length, chars) {
        // http://stackoverflow.com/a/10727155/28004
        var mask = '';
        if (chars.indexOf('a') > -1) mask += 'abcdefghijklmnopqrstuvwxyz';
        if (chars.indexOf('A') > -1) mask += 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
        if (chars.indexOf('#') > -1) mask += '0123456789';
        if (chars.indexOf('!') > -1) mask += '~`!@#$%^&*()_+-={}[]:";\'<>?,./|\\';
        var result = '';
        for (var i = length; i > 0; --i) result += mask[Math.floor(Math.random() * mask.length)];
        return result;
    }

}

after a grunt task I end up having a single .js file starting as:

var MyCustomScript = 
/******/ (function(modules) { // webpackBootstrap
/******/    // The module cache
/******/    var installedModules = {};

/******/    // The require function
/******/    function __webpack_require__(moduleId) {

/******/        // Check if module is in cache
/******/        if(installedModules[moduleId])
/******/            return installedModules[moduleId].exports;

/******/        // Create a new module (and put it into the cache)
/******/        var module = installedModules[moduleId] = {
/******/            exports: {},
/******/            id: moduleId,
/******/            loaded: false
/******/        };
...

and I use it normally in my HTML code as:

<script src="/dist/myscript.js"></script>
<script>
    var my       = new MyCustomScript(document, true),
        password = my.generateRandomId(8, "Aa");

    my.$("#password").text(password);
</script>

all works fine... the issue is, I would like to have intellisese in VSCode (or Atom for the that matter) when I press the . after my...

I've tried to add

/// <reference path="/dist/myscript.js" />

at the top of the HTML but no luck... what is the correct method?

balexandre
  • 73,608
  • 45
  • 233
  • 342
  • You can trigger IntelliSense in any editor window by typing Ctrl+Space or by typing a trigger character (such as the dot character (.) in JavaScript). – Kasiriveni May 23 '17 at 11:38
  • try this https://code.visualstudio.com/docs/editor/intellisense#_customizing-intellisense – Kasiriveni May 23 '17 at 11:40
  • @Kasiriveni I have intellisense for other libraries, like in node, just, how can I tell my template HTML file that the variable `my` is of `MyCustomScript` type and should show me all methods available? – balexandre May 23 '17 at 11:46

0 Answers0