p5.js-web-editor icon indicating copy to clipboard operation
p5.js-web-editor copied to clipboard

p5.js library Autocomplete and/or link to specific parts of reference

Open shiffman opened this issue 9 years ago • 10 comments

Students requested a link to the p5.js reference in the editor. Ideally we would also eventually have an option where you could highlight a function name like fill, right-click, and have a "find in reference" option.

shiffman avatar Sep 16 '16 14:09 shiffman

We could also consider features like autocomplete, definitions in the editor, and so on, using Tern.js. I found an example of using it with CodeMirror as well..

catarak avatar Sep 16 '16 22:09 catarak

In the mean time, maybe we could just put a link to the reference https://p5js.org/reference/ somewhere in the editor menu bar?

zhuoxi avatar Sep 17 '16 15:09 zhuoxi

Ive tried compiling a tern definitions json file for p5 with tern's "condense" tool but it failed to work. Ive even tried it with other libraries like Three.js and jquery, and it worked. So condense works fine; I think the problem is the script. This was the command and the output : ****@**** MINGW64 ~/AppData/Roaming/Brackets/extensions/user/ternific/node_modules/tern/bin $ ./condense --name p /c/wamp/www/libraries/p5.js { "!name": "p" }

ducklin5 avatar Jan 05 '17 13:01 ducklin5

@ducklin5 I've never used tern before so I'm not sure how to help... want to give me more details as to what you've done so far and maybe we can attack it together?

catarak avatar Jan 06 '17 17:01 catarak

Yes! Im using tern on brackets and on sublime text. Ive got no experience with it either and Im just trying to follow the manual and guides that Ive found googling. From what I gather we can use the "condense" tool that comes with it to compile a json file of definition and autocomplete terms for p5. Another option is the configure the yuidoc to format the output in the same format as that of tern.

ducklin5 avatar Jan 07 '17 20:01 ducklin5

Autocomplete file: https://p5js.org/reference/data.json

catarak avatar May 24 '17 17:05 catarak

@catarak, is this json file a tern plugin or auto completion specifically for the p5 web editor?

ducklin5 avatar Jun 23 '17 06:06 ducklin5

@ducklin5 it's the output of running grunt on the p5 source. it's basically all the p5 documentation in JSON form. i'm working on getting it to a format that works with tern. here's a gist of that process so far: https://gist.github.com/kaganjd/32c87c49fda5f61b78aa2b88993daca4

kaganjd avatar Jun 23 '17 17:06 kaganjd

@catarak if this issue still not done.. I will be happy to work on this.

ash97531 avatar Mar 22 '22 07:03 ash97531

y not just add typescript integration ? (i'd recommend switching to the monaco editor for this )

jonnytest1 avatar Jul 16 '22 18:07 jonnytest1

The autocompletion is actually very easy to do using @codemirror/autocomplete once we upgrade to CodeMirror v6.

image

import { completeFromList, autocompletion } from '@codemirror/autocomplete';

import {
  p5FunctionKeywords,
  p5VariableKeywords
} from '../../../utils/p5-keywords';

const p5AutocompleteSource = completeFromList(
  Object.keys(p5FunctionKeywords)
    .map((keyword) => ({
      label: keyword,
      type: 'function',
      boost: 99 // TODO: detail
    }))
    .concat(
      Object.keys(p5VariableKeywords).map((keyword) => ({
        label: keyword,
        type: 'constant',
        boost: 50 // TODO: detail
      }))
    )
);

const p5AutocompleteExt = autocompletion({
  override: [p5AutocompleteSource] // TODO: include native JS
});

And then you include that p5AutocompleteExt object in the extensions array when creating the EditorView.

lindapaiste avatar May 13 '23 23:05 lindapaiste