Avatar for neshanjo

neshanjo

Member since May 2021 • Last active Jul 2021
  • 1 conversations
  • 8 comments

Most recent activity

  • in General
    Avatar for neshanjo

    @JumJum code.replace(selected, ... is dangerous since it may also override other places that, by accident, contain the same code as the selection. There are better ways by using start and end of the selection and replacing only this part - but, again, let us leave this to another PR (that we'd be happy to receive from you!).

    Edit: Have a look at https://codemirror.net/doc/manual.html#a­pi and try using Espruino.Core.EditorJavaScript.getCodeMi­rror().replaceSelection(...). This should do the trick.

  • in General
    Avatar for neshanjo

    https://prettier.io/docs/en/ignore.html#­javascript

    You can ignore certain lines/parts of the code with this special comment.

    Implemeting "format only the selected code" is possible by using the Editor properties. This could be the next feature in another PR.

  • in General
    Avatar for neshanjo
      function formatCode() {
        var code = Espruino.Core.EditorJavaScript.getCode()­;
        var cursor = Espruino.Core.EditorJavaScript.getCodeMi­rror().getCursor();
        code = prettier.format(code, {
          parser: "babel",
          plugins: prettierPlugins,
          tabWidth: parseInt(Espruino.Config.TAB_SIZE),
          useTabs: Espruino.Config.INDENTATION_TYPE == "tabs",
          semi: true,
          singleQuote: true
        });
        Espruino.Core.EditorJavaScript.setCode(c­ode);
        Espruino.Core.EditorJavaScript.getCodeMi­rror().setCursor(cursor);
      }
    

    get/setCursor principally seems to do the trick, however, it changes the scrolling position. The line with the cursor becomes the last line in the editor window. You can try this by e.g. using large app code like https://github.com/espruino/BangleApps/b­lob/master/apps/trex/trex.js
    Any ideas how to fix this?

  • in General
    Avatar for neshanjo

    @JumJum Sorry for the delay and thanks very much for your code. This is exactly the kind of starting point I needed.

    Prettier doesn't need an internet connection, either. Here is what I did based on your initial example using prettier: https://github.com/neshanjo/EspruinoWebI­DE/tree/code-formatting-prettier
    Anybody here interested in this, can just checkout my fork and run npm install followed by npm start.

    My code also respects the indentation settings (tab width and tabs versus spaces).

    Indeed, there is still some work to do:

    1. Save the current cursor position
    2. Hide the icon in Blockly mode
    3. Add a keyboard shortcut
    4. Maybe another icon.

    I don't think, we need a settings page, though. I even think we should not have one in order to follow one code style. That's the idea behind prettier.

    I also made another branch using js-beautify: https://github.com/neshanjo/EspruinoWebI­DE/tree/code-formatting-js-beautify

    IMO, the main (only?) advantage of js-beautify over prettier is the smaller size. Prettier is more or less THE standard in modern JS development and available in many code editors and even from the command line. This is a nice feature, especially for BangleJS where every app uses its own code formatting style. Furthermore, it is actively developed by a large team, while js-beautify claims on their Github page that they are in need of more contributors.

    Just my 2ct. I'd be very happy to have any kind of code formatting soon.

    My next steps are to work on point 1 (see list above) and submit a MR. 2+3 should be done very easily by someone more familiar with the project.

  • in General
    Avatar for neshanjo

    Thanks. I've seen the the Github repo for EspruinoWebIDE. Anyway, it will take some time to understand how everything works... Maybe already some simple questions: Should this be implemented as a plugin? How can the formatter be registered to a certain key combination?

    And, regarding the beautifier link, why not use prettier?

    https://prettier.io/
    https://prettier.io/docs/en/browser.html­

    It is also open source and supported in almost any IDE - so it would provide consistent results also between different tools...

  • in General
    Avatar for neshanjo

    Hi together, I'd like to bring attention to this topic again. I think it would be really great to have a code formatter available. Not only does it unify our code base e.g. in BangleApps, it can also prevent bugs (for instance, the typical if without braces problems, see https://softwareengineering.stackexchang­e.com/a/16530). I'm also willing to help implementing this (however, I'm not familiar with the code of EspruineWebIDE yet, so I'd need some help where to get started).

  • in Bangle.js
    Avatar for neshanjo

    Many thanks for your quick reply! Indeed, the Readme answers all the remaining questions. I wasn't aware of the fact that the settings are just another app, so I did not look for it in the BangleApps repo.

  • in Bangle.js
    Avatar for neshanjo

    Hi there,

    I have some questions regarding bluetooth settings:

    1. What does "Make Connectable" do and how is it different from the setting in the BLE submenu?
    2. I guess BLE on/off in the BLE menu is the overall Bluetooth on/off switch. What does "Programmable" mean?
    3. BLE on and Programmable off seems to work with GadgetBridge. But, when GB loses connection, can other people still connect and read data?
    4. Which are the recommended settings that nobody else can access my watch, but I can still use GadgetBrigde? I tried Whilelist -> Add device, but it always shows "Connect device to add to whitelist", even though I'm connected via GB or via Web Bluetooth.

    Kind regards,
    neshanjo

Actions