abe33 / atom-figlet

Converts a selection into ascii-art using figlet
MIT License
15 stars 5 forks source link

Uncaught TypeError: editor.getCommentStrings is not a function #9

Open XanderXAJ opened 7 years ago

XanderXAJ commented 7 years ago

Steps to reproduce:

  1. Select text.
  2. Run the convert action.
  3. Select a font.

The error is thrown immediately. I assume it's because APIs have changed in newer Atom versions.

Atom: 1.23.0-beta1 x64 Electron: 1.6.15 OS: Mac OS X 10.13.1 Thrown From: figlet package 0.5.4

Stack Trace

Uncaught TypeError: editor.getCommentStrings is not a function

At /Users/alexp/.atom/packages/figlet/lib/figlet.coffee:68

TypeError: editor.getCommentStrings is not a function
    at Object.getTextToConvert (/packages/figlet/lib/figlet.coffee:68:117)
    at Object.convert (/packages/figlet/lib/figlet.coffee:38:44)
    at FigletFontView.module.exports.FigletFontView.confirmed (/packages/figlet/lib/figlet-font-view.coffee:62:20)
    at FigletFontView.module.exports.SelectListView.confirmSelection (/packages/git-plus/node_modules/atom-space-pen-views/lib/select-list-view.js:338:21)
    at /packages/git-plus/node_modules/atom-space-pen-views/lib/select-list-view.js:109:19)
    at CommandRegistry.handleCommandEvent (/Applications/Atom Beta.app/Contents/Resources/app/src/command-registry.js:388:36)
    at KeymapManager.module.exports.KeymapManager.dispatchCommandEvent (/Applications/Atom Beta.app/Contents/Resources/app/node_modules/atom-keymap/lib/keymap-manager.js:621:22)
    at KeymapManager.module.exports.KeymapManager.handleKeyboardEvent (/Applications/Atom Beta.app/Contents/Resources/app/node_modules/atom-keymap/lib/keymap-manager.js:412:28)
    at WindowEventHandler.handleDocumentKeyEvent (/Applications/Atom Beta.app/Contents/Resources/app/src/window-event-handler.js:108:40)

Commands

  4x -2:23.7.0 core:confirm (input.hidden-input)
     -0:36.9.0 pane:show-next-recently-used-item (atom-workspace.workspace.scrollbars-visible-always.theme-one-dark-syntax.theme-one-dark-ui.teletype-Guest)
     -0:36.8.0 pane:move-active-item-to-top-of-stack (atom-workspace.workspace.scrollbars-visible-always.theme-one-dark-syntax.theme-one-dark-ui.teletype-Guest)
     -0:33.4.0 pane:show-next-recently-used-item (input.hidden-input)
     -0:33.2.0 pane:move-active-item-to-top-of-stack (div.panels-item)
     -0:28.2.0 pane:show-next-recently-used-item (input.hidden-input)
     -0:28.1.0 pane:move-active-item-to-top-of-stack (input.hidden-input)
  2x -0:25.8.0 editor:newline (input.hidden-input)
     -0:19.8.0 editor:select-to-beginning-of-word (input.hidden-input)
     -0:17.9.0 command-palette:toggle (input.hidden-input)
     -0:15.5.0 core:confirm (input.hidden-input)
     -0:15.5.0 figlet:convert (input.hidden-input)
  6x -0:14.6.0 core:move-up (input.hidden-input)
     -0:13.5.0 core:confirm (input.hidden-input)
     -0:11.9.0 editor:consolidate-selections (input.hidden-input)
     -0:11.9.0 core:cancel (input.hidden-input)

Non-Core Packages

advanced-open-file 0.16.7 
atom-notes 1.14.2 
atom-terminal 0.8.0 
autocomplete-python 1.10.3 
autocomplete-xml 0.9.4 
busy-signal 1.4.3 
change-case 0.6.5 
custom-title 1.0.1 
figlet 0.5.4 
file-icons 2.1.13 
geiger 2.1.0 
git-plus 7.10.0 
git-time-machine 1.5.9 
gutter-shadow 1.1.0 
highlight-selected 0.13.1 
indent-guide-improved 1.4.13 
intentions 1.1.5 
language-docker 1.1.8 
language-groovy 0.7.0 
language-powershell 4.0.0 
language-puppet 0.23.0 
language-tcl 0.1.2 
less-than-slash 0.17.0 
linter 2.2.0 
linter-js-yaml 1.2.8 
linter-puppet-lint 0.8.4 
linter-puppet-parser 0.1.1 
linter-pylint 2.1.0 
linter-ui-default 1.6.10 
markdown-writer 2.7.3 
merge-conflicts 1.4.5 
minimap 4.29.7 
minimap-bookmarks 0.4.2 
minimap-cursorline 0.2.0 
minimap-find-and-replace 4.5.2 
minimap-git-diff 4.3.1 
minimap-highlight-selected 4.6.1 
minimap-selection 4.5.0 
minimap-split-diff 0.3.7 
project-manager 3.3.5 
project-plus 1.0.0 
react 0.17.0 
rename-tabs 0.2.0 
revert-buffer 0.6.0 
sort-lines 0.18.0 
split-diff 1.5.1 
sync-settings 0.8.3 
tabularize 0.2.5 
teletype 0.1.2 
valign 1.1.3 
wordcount 2.10.4 
danielhickman commented 6 years ago

I forked it to test a change I found on another package and it works.

// -
editor.getCommentStrings(scope)

// +
editor.getScopedSettingsDelegate().getCommentStrings(scope)

I just Googled the error and plopped in the change from nteract/hydrogen. I haven't spent enough time tinkering with Atom packages to know about the API and how it'll affect each version. I just had a free moment to tinker with this line and test on my machine.

I don't think it's enough to warrant a PR since I didn't do testing for older Atom versions and it's such a small change.

pcdgroup commented 6 years ago

This fix worked for me. It looks like the author isn't paying attention or has abandoned this project...? - @danielhickman maybe you should go ahead and submit a pull request to try and get their attention.

danielhickman commented 6 years ago

@pcdgroup I'm sure he's just busy but I'll go ahead and submit a PR, but discussion will probably need to take place there about how to move forward with support for older versions.

danielhickman commented 6 years ago

Done > #10.

I overwrote my existing test commit with a simple check for the function as the previous did. This should still support the older versions I can't test due to the time it takes to use multiple instances of Atom since I'm [again] unfamiliar with Atom's core.

mischnu commented 6 years ago

Sorry, my mistake: just created a new issue #11 that's actually only related to #10.

Shonen17 commented 6 years ago

I don't know if I do it well, first time I comment on this website. But no one of your correction work on my Atom version (1.25.0).

This is what I do to correct it :

//68 //- {commentStartString, commentEndString} = editor.languageMode.commentStartAndEndStringsForScope?(scope) ? editor.getCommentStrings(scope) //68 //+ {commentStartString, commentEndString} = editor.languageMode.commentStartAndEndStringsForScope?(scope) ? editor.tokenizedBuffer.commentStringsForPosition(editor.getCursorBufferPosition())

Find here : https://github.com/nteract/hydrogen/pull/1147/files

Sorry for bad English but I hope this can help.

stanmarc commented 5 years ago

This is my hack to overcome identification of commented strings (only for // and #, add others in the array if needed)

Replace this: (lines 69 to 79 in .atom\packages\figlet\lib\figlet.coffee)

    {commentStartString, commentEndString} = editor.languageMode.commentStartAndEndStringsForScope?(scope) ? editor.getCommentStrings(scope)

    if commentStartString?
      commentStartRegexString = escapeRegExp(commentStartString).replace(/(\s+)$/, '')
      commentStartRegex = new RegExp("^(\\s*)(#{commentStartRegexString})*\\s+")

      match = commentStartRegex.exec(selectionText)

      if match?
        {length} = match[0]
        start.column += length
        selectionText = selectionText[length..-1]

with this:

    for key in ['//', '#']
      commentStartRegexString = escapeRegExp(key)
      commentStartRegex = new RegExp("^(\\s*)(#{commentStartRegexString})*\\s+")

      match = commentStartRegex.exec(selectionText)
      if match?
        {length} = match[0]
        start.column += length
        selectionText = selectionText[length..-1]
Shonen17 commented 5 years ago

Ok, now it does not support anymore the keystroke ctrl-alt-shift-F for the command figlet:convert-last Now i used another package with minimap and it works perfectly. This one is out of date.

stanmarc commented 5 years ago

Hm...

I have the latest (1.40.1 x64 Windows based) version of Atom and just now tried the ctrl-alt-shift-F and it still works as usual. I have tried your suggested package, the minimap-titles, but it clashes with some another package and attempts to create a block comment:

    /**
         * Block comment
         *
         * @param type
         * @return void
    ██   ██ ███████ ██      ██       ██████      ██     ██  ██████  ██████  ██      ██████
    ██   ██ ██      ██      ██      ██    ██     ██     ██ ██    ██ ██   ██ ██      ██   ██
    ███████ █████   ██      ██      ██    ██     ██  █  ██ ██    ██ ██████  ██      ██   ██
    ██   ██ ██      ██      ██      ██    ██     ██ ███ ██ ██    ██ ██   ██ ██      ██   ██
    ██   ██ ███████ ███████ ███████  ██████       ███ ███   ██████  ██   ██ ███████ ██████
    */

Then, the package lacks a interface to choose fonts (you have to set your ASCI font through the config file).

pdnataraj commented 3 years ago

@stanmarc your solution worked for me, (including the ctrl-alt-f command), thanks!