720 } |
785 } |
721 |
786 |
722 // Table of commands -- with command forms, argument kinds, help message, implementation, ... |
787 // Table of commands -- with command forms, argument kinds, help message, implementation, ... |
723 |
788 |
724 { |
789 { |
725 registerCommand(new Command("/list", "[all|start|history|<name or id>]", "list the source you have typed", |
790 registerCommand(new Command("/list", "[all|start|<name or id>]", "list the source you have typed", |
726 arg -> cmdList(arg), |
791 "Show the source of snippets, prefaced with the snippet id.\n\n" + |
727 editKeywordCompletion())); |
792 "/list\n" + |
728 registerCommand(new Command("/seteditor", "<executable>", "set the external editor command to use", |
793 " -- List the currently active snippets of code that you typed or read with /open\n" + |
729 arg -> cmdSetEditor(arg), |
794 "/list start\n" + |
730 EMPTY_COMPLETION_PROVIDER)); |
795 " -- List the automatically evaluated start-up snippets\n" + |
|
796 "/list all\n" + |
|
797 " -- List all snippets including failed, overwritten, dropped, and start-up\n" + |
|
798 "/list <name>\n" + |
|
799 " -- List snippets with the specified name (preference for active snippets)\n" + |
|
800 "/list <id>\n" + |
|
801 " -- List the snippet with the specified snippet id\n", |
|
802 arg -> cmdList(arg), |
|
803 editKeywordCompletion())); |
|
804 registerCommand(new Command("/seteditor", "<command>", "set the external editor command to use", |
|
805 "Specify the command to launch for the /edit command.\n" + |
|
806 "The command is an operating system dependent string.\n" + |
|
807 "The command may include space-separated arguments (such as flags).\n" + |
|
808 "When /edit is used, temporary file to edit will be appended as the last argument.\n", |
|
809 arg -> cmdSetEditor(arg), |
|
810 EMPTY_COMPLETION_PROVIDER)); |
731 registerCommand(new Command("/edit", "<name or id>", "edit a source entry referenced by name or id", |
811 registerCommand(new Command("/edit", "<name or id>", "edit a source entry referenced by name or id", |
732 arg -> cmdEdit(arg), |
812 "Edit a snippet or snippets of source in an external editor.\n" + |
733 editCompletion())); |
813 "The editor to use is set with /seteditor.\n" + |
|
814 "If no editor has been set, a simple editor will be launched.\n\n" + |
|
815 "/edit <name>\n" + |
|
816 " -- Edit the snippet or snippets with the specified name (preference for active snippets)\n" + |
|
817 "/edit <id>\n" + |
|
818 " -- Edit the snippet with the specified snippet id\n" + |
|
819 "/edit\n" + |
|
820 " -- Edit the currently active snippets of code that you typed or read with /open\n", |
|
821 arg -> cmdEdit(arg), |
|
822 editCompletion())); |
734 registerCommand(new Command("/drop", "<name or id>", "delete a source entry referenced by name or id", |
823 registerCommand(new Command("/drop", "<name or id>", "delete a source entry referenced by name or id", |
735 arg -> cmdDrop(arg), |
824 "Drop a snippet -- making it inactive.\n\n" + |
736 editCompletion(), |
825 "/drop <name>\n" + |
737 CommandKind.REPLAY)); |
826 " -- Drop the snippet with the specified name\n" + |
738 registerCommand(new Command("/save", "[all|history|start] <file>", "save: <none> - current source;\n" + |
827 "/drop <id>\n" + |
739 " all - source including overwritten, failed, and start-up code;\n" + |
828 " -- Drop the snippet with the specified snippet id\n", |
740 " history - editing history;\n" + |
829 arg -> cmdDrop(arg), |
741 " start - default start-up definitions", |
830 editCompletion(), |
742 arg -> cmdSave(arg), |
831 CommandKind.REPLAY)); |
743 saveCompletion())); |
832 registerCommand(new Command("/save", "[all|history|start] <file>", "Save snippet source to a file.", |
|
833 "Save the specified snippets and/or commands to the specified file.\n\n" + |
|
834 "/save <file>\n" + |
|
835 " -- Save the source of current active snippets to the file\n" + |
|
836 "/save all <file>\n" + |
|
837 " -- Save the source of all snippets to the file\n" + |
|
838 " Includes source including overwritten, failed, and start-up code\n" + |
|
839 "/save history <file>\n" + |
|
840 " -- Save the sequential history of all commands and snippets entered since jshell was launched\n" + |
|
841 "/save start <file>\n" + |
|
842 " -- Save the default start-up definitions to the file\n", |
|
843 arg -> cmdSave(arg), |
|
844 saveCompletion())); |
744 registerCommand(new Command("/open", "<file>", "open a file as source input", |
845 registerCommand(new Command("/open", "<file>", "open a file as source input", |
745 arg -> cmdOpen(arg), |
846 "Open a file and read its contents as snippets and commands.\n\n" + |
746 FILE_COMPLETION_PROVIDER)); |
847 "/open <file>\n" + |
|
848 " -- Read the specified file as jshell input.\n", |
|
849 arg -> cmdOpen(arg), |
|
850 FILE_COMPLETION_PROVIDER)); |
747 registerCommand(new Command("/vars", null, "list the declared variables and their values", |
851 registerCommand(new Command("/vars", null, "list the declared variables and their values", |
748 arg -> cmdVars(), |
852 "List the type, name, and value of the current active jshell variables.\n", |
749 EMPTY_COMPLETION_PROVIDER)); |
853 arg -> cmdVars(), |
|
854 EMPTY_COMPLETION_PROVIDER)); |
750 registerCommand(new Command("/methods", null, "list the declared methods and their signatures", |
855 registerCommand(new Command("/methods", null, "list the declared methods and their signatures", |
751 arg -> cmdMethods(), |
856 "List the name, parameter types, and return type of the current active jshell methods.\n", |
752 EMPTY_COMPLETION_PROVIDER)); |
857 arg -> cmdMethods(), |
|
858 EMPTY_COMPLETION_PROVIDER)); |
753 registerCommand(new Command("/classes", null, "list the declared classes", |
859 registerCommand(new Command("/classes", null, "list the declared classes", |
754 arg -> cmdClasses(), |
860 "List the current active jshell classes, interfaces, and enums.\n", |
755 EMPTY_COMPLETION_PROVIDER)); |
861 arg -> cmdClasses(), |
|
862 EMPTY_COMPLETION_PROVIDER)); |
756 registerCommand(new Command("/imports", null, "list the imported items", |
863 registerCommand(new Command("/imports", null, "list the imported items", |
757 arg -> cmdImports(), |
864 "List the current active jshell imports.\n", |
758 EMPTY_COMPLETION_PROVIDER)); |
865 arg -> cmdImports(), |
759 registerCommand(new Command("/exit", null, "exit the REPL", |
866 EMPTY_COMPLETION_PROVIDER)); |
760 arg -> cmdExit(), |
867 registerCommand(new Command("/exit", null, "exit jshell", |
761 EMPTY_COMPLETION_PROVIDER)); |
868 "Leave the jshell tool. No work is saved.\n" + |
762 registerCommand(new Command("/reset", null, "reset everything in the REPL", |
869 "Save any work before using this command\n", |
763 arg -> cmdReset(), |
870 arg -> cmdExit(), |
764 EMPTY_COMPLETION_PROVIDER)); |
871 EMPTY_COMPLETION_PROVIDER)); |
|
872 registerCommand(new Command("/reset", null, "reset jshell", |
|
873 "Reset the jshell tool code and execution state:\n" + |
|
874 " * All entered code is lost.\n" + |
|
875 " * Start-up code is re-executed.\n" + |
|
876 " * The execution state is restarted.\n" + |
|
877 " * The classpath is cleared.\n" + |
|
878 "Tool settings are maintained: /feedback, /prompt, and /seteditor\n" + |
|
879 "Save any work before using this command\n", |
|
880 arg -> cmdReset(), |
|
881 EMPTY_COMPLETION_PROVIDER)); |
765 registerCommand(new Command("/reload", "[restore] [quiet]", "reset and replay relevant history -- current or previous (restore)", |
882 registerCommand(new Command("/reload", "[restore] [quiet]", "reset and replay relevant history -- current or previous (restore)", |
766 arg -> cmdReload(arg), |
883 "Reset the jshell tool code and execution state then replay each\n" + |
767 reloadCompletion())); |
884 "jshell valid command and valid snippet in the order they were entered.\n\n" + |
|
885 "/reload\n" + |
|
886 " -- Reset and replay the valid history since jshell was entered, or\n" + |
|
887 " a /reset, or /reload command was executed -- whichever is most\n" + |
|
888 " recent.\n" + |
|
889 "/reload restore\n" + |
|
890 " -- Reset and replay the valid history between the previous and most\n" + |
|
891 " recent time that jshell was entered, or a /reset, or /reload\n" + |
|
892 " command was executed. This can thus be used to restore a previous\n" + |
|
893 " jshell tool sesson.\n" + |
|
894 "/reload [restore] quiet\n" + |
|
895 " -- With the 'quiet' argument the replay is not shown. Errors will display.\n", |
|
896 arg -> cmdReload(arg), |
|
897 reloadCompletion())); |
768 registerCommand(new Command("/feedback", "<level>", "feedback information: off, concise, normal, verbose, default, or ?", |
898 registerCommand(new Command("/feedback", "<level>", "feedback information: off, concise, normal, verbose, default, or ?", |
769 arg -> cmdFeedback(arg), |
899 "Set the level of feedback describing the effect of commands and snippets.\n\n" + |
770 new FixedCompletionProvider("off", "concise", "normal", "verbose", "default", "?"))); |
900 "/feedback off\n" + |
|
901 " -- Give no feedback\n" + |
|
902 "/feedback concise\n" + |
|
903 " -- Brief and generally symbolic feedback\n" + |
|
904 "/feedback normal\n" + |
|
905 " -- Give a natural language description of the actions\n" + |
|
906 "/feedback verbose\n" + |
|
907 " -- Like normal but with side-effects described\n" + |
|
908 "/feedback default\n" + |
|
909 " -- Same as normal for user input, off for input from a file\n", |
|
910 arg -> cmdFeedback(arg), |
|
911 new FixedCompletionProvider("off", "concise", "normal", "verbose", "default", "?"))); |
771 registerCommand(new Command("/prompt", null, "toggle display of a prompt", |
912 registerCommand(new Command("/prompt", null, "toggle display of a prompt", |
772 arg -> cmdPrompt(), |
913 "Toggle between displaying an input prompt and not displaying a prompt.\n" + |
773 EMPTY_COMPLETION_PROVIDER)); |
914 "Particularly useful when pasting large amounts of text.\n", |
|
915 arg -> cmdPrompt(), |
|
916 EMPTY_COMPLETION_PROVIDER)); |
774 registerCommand(new Command("/classpath", "<path>", "add a path to the classpath", |
917 registerCommand(new Command("/classpath", "<path>", "add a path to the classpath", |
775 arg -> cmdClasspath(arg), |
918 "Append a additional path to the classpath.\n", |
776 classPathCompletion(), |
919 arg -> cmdClasspath(arg), |
777 CommandKind.REPLAY)); |
920 classPathCompletion(), |
|
921 CommandKind.REPLAY)); |
778 registerCommand(new Command("/history", null, "history of what you have typed", |
922 registerCommand(new Command("/history", null, "history of what you have typed", |
779 arg -> cmdHistory(), |
923 "Display the history of snippet and command input since this jshell was launched.\n", |
780 EMPTY_COMPLETION_PROVIDER)); |
924 arg -> cmdHistory(), |
|
925 EMPTY_COMPLETION_PROVIDER)); |
781 registerCommand(new Command("/setstart", "<file>", "read file and set as the new start-up definitions", |
926 registerCommand(new Command("/setstart", "<file>", "read file and set as the new start-up definitions", |
782 arg -> cmdSetStart(arg), |
927 "The contents of the specified file become the default start-up snippets and commands.\n", |
783 FILE_COMPLETION_PROVIDER)); |
928 arg -> cmdSetStart(arg), |
784 registerCommand(new Command("/debug", "", "toggle debugging of the REPL", |
929 FILE_COMPLETION_PROVIDER)); |
785 arg -> cmdDebug(arg), |
930 registerCommand(new Command("/debug", null, "toggle debugging of the jshell", |
786 EMPTY_COMPLETION_PROVIDER, |
931 "Display debugging information for the jshelll implementation.\n" + |
787 CommandKind.HIDDEN)); |
932 "0: Debugging off\n" + |
788 registerCommand(new Command("/help", "", "this help message", |
933 "r: Debugging on\n" + |
789 arg -> cmdHelp(), |
934 "g: General debugging on\n" + |
790 EMPTY_COMPLETION_PROVIDER)); |
935 "f: File manager debugging on\n" + |
791 registerCommand(new Command("/?", "", "this help message", |
936 "c': Completion analysis debugging on\n" + |
792 arg -> cmdHelp(), |
937 "d': Dependency debugging on\n" + |
793 EMPTY_COMPLETION_PROVIDER)); |
938 "e': Event debugging on\n", |
|
939 arg -> cmdDebug(arg), |
|
940 EMPTY_COMPLETION_PROVIDER, |
|
941 CommandKind.HIDDEN)); |
|
942 registerCommand(new Command("/help", "[<command>|<subject>]", "get information about jshell", |
|
943 "Display information about jshell.\n" + |
|
944 "/help\n" + |
|
945 " -- List the jshell commands and help subjects.\n" + |
|
946 "/help <command>\n" + |
|
947 " -- Display information about the specified comand. The slash must be included.\n" + |
|
948 " Only the first few letters of the command are needed -- if more than one\n" + |
|
949 " each will be displayed. Example: /help /li\n" + |
|
950 "/help <subject>\n" + |
|
951 " -- Display information about the specified help subject. Example: /help intro\n", |
|
952 arg -> cmdHelp(arg), |
|
953 EMPTY_COMPLETION_PROVIDER)); |
|
954 registerCommand(new Command("/?", "", "get information about jshell", |
|
955 "Display information about jshell (abbreviation for /help).\n" + |
|
956 "/?\n" + |
|
957 " -- Display list of commands and help subjects.\n" + |
|
958 "/? <command>\n" + |
|
959 " -- Display information about the specified comand. The slash must be included.\n" + |
|
960 " Only the first few letters of the command are needed -- if more than one\n" + |
|
961 " match, each will be displayed. Example: /? /li\n" + |
|
962 "/? <subject>\n" + |
|
963 " -- Display information about the specified help subject. Example: /? intro\n", |
|
964 arg -> cmdHelp(arg), |
|
965 EMPTY_COMPLETION_PROVIDER)); |
794 registerCommand(new Command("/!", "", "re-run last snippet", |
966 registerCommand(new Command("/!", "", "re-run last snippet", |
795 arg -> cmdUseHistoryEntry(-1), |
967 "Reevaluate the most recently entered snippet.\n", |
796 EMPTY_COMPLETION_PROVIDER)); |
968 arg -> cmdUseHistoryEntry(-1), |
797 registerCommand(new Command("/<id>", "", "re-run snippet by id", |
969 EMPTY_COMPLETION_PROVIDER)); |
798 arg -> { throw new IllegalStateException(); }, |
970 |
799 EMPTY_COMPLETION_PROVIDER, |
971 // Documentation pseudo-commands |
800 CommandKind.HELP_ONLY)); |
972 |
801 registerCommand(new Command("/-<n>", "", "re-run n-th previous snippet", |
973 registerCommand(new Command("/<id>", "re-run snippet by id", |
802 arg -> { throw new IllegalStateException(); }, |
974 "", |
803 EMPTY_COMPLETION_PROVIDER, |
975 CommandKind.HELP_ONLY)); |
804 CommandKind.HELP_ONLY)); |
976 registerCommand(new Command("/-<n>", "re-run n-th previous snippet", |
|
977 "", |
|
978 CommandKind.HELP_ONLY)); |
|
979 registerCommand(new Command("intro", "An introduction to the jshell tool", |
|
980 "The jshell tool allows you to execute Java code, getting immediate results.\n" + |
|
981 "You can enter a Java definition (variable, method, class, etc), like: int x = 8\n" + |
|
982 "or a Java expression, like: x + x\n" + |
|
983 "or a Java statement or import.\n" + |
|
984 "These little chunks of Java code are called 'snippets'.\n\n" + |
|
985 "There are also jshell commands that allow you to understand and\n" + |
|
986 "control what you are doing, like: /list\n\n" + |
|
987 "For a list of commands: /help", |
|
988 CommandKind.HELP_SUBJECT)); |
|
989 registerCommand(new Command("shortcuts", "Describe shortcuts", |
|
990 "Supported shortcuts include:\n\n" + |
|
991 "<tab> -- After entering the first few letters of a Java identifier,\n" + |
|
992 " a jshell command, or, in some cases, a jshell command argument,\n" + |
|
993 " press the <tab> key to complete the input.\n" + |
|
994 " If there is more than one completion, show possible completions.\n" + |
|
995 "Shift-<tab> -- After the name and open parenthesis of a method or constructor invocation,\n" + |
|
996 " hold the <shift> key and press the <tab> to see a synopsis of all\n" + |
|
997 " matching methods/constructors.\n", |
|
998 CommandKind.HELP_SUBJECT)); |
805 } |
999 } |
806 |
1000 |
807 public List<Suggestion> commandCompletionSuggestions(String code, int cursor, int[] anchor) { |
1001 public List<Suggestion> commandCompletionSuggestions(String code, int cursor, int[] anchor) { |
808 String prefix = code.substring(0, cursor); |
1002 String prefix = code.substring(0, cursor); |
809 int space = prefix.indexOf(' '); |
1003 int space = prefix.indexOf(' '); |