Code complete fixes and changelog
This commit is contained in:
parent
371932e085
commit
d8797aa805
@ -27,108 +27,68 @@ import {
|
|||||||
} from "./deps.ts";
|
} from "./deps.ts";
|
||||||
import { highlightingDirectiveParser } from "./markdown_parser/parser.ts";
|
import { highlightingDirectiveParser } from "./markdown_parser/parser.ts";
|
||||||
|
|
||||||
const languageCache = new Map<string, Language>();
|
export const builtinLanguages: Record<string, Language> = {
|
||||||
|
"meta": StreamLanguage.define(yamlLanguage),
|
||||||
export function languageFor(name: string): Language | null {
|
"yaml": StreamLanguage.define(yamlLanguage),
|
||||||
if (languageCache.has(name)) {
|
"template": StreamLanguage.define(yamlLanguage),
|
||||||
return languageCache.get(name)!;
|
"embed": StreamLanguage.define(yamlLanguage),
|
||||||
}
|
"data": StreamLanguage.define(yamlLanguage),
|
||||||
const language = languageLookup(name);
|
"javascript": javascriptLanguage,
|
||||||
if (!language) {
|
"js": javascriptLanguage,
|
||||||
return null;
|
"typescript": typescriptLanguage,
|
||||||
}
|
"ts": typescriptLanguage,
|
||||||
languageCache.set(name, language);
|
"sql": StreamLanguage.define(sqlLanguage),
|
||||||
return language;
|
"postgresql": StreamLanguage.define(postgresqlLanguage),
|
||||||
}
|
"pgsql": StreamLanguage.define(postgresqlLanguage),
|
||||||
|
"postgres": StreamLanguage.define(postgresqlLanguage),
|
||||||
function languageLookup(name: string): Language | null {
|
"rust": StreamLanguage.define(rustLanguage),
|
||||||
switch (name) {
|
"rs": StreamLanguage.define(rustLanguage),
|
||||||
case "meta":
|
"css": StreamLanguage.define(sqlLanguage),
|
||||||
case "yaml":
|
"html": htmlLanguage,
|
||||||
case "template":
|
"python": StreamLanguage.define(pythonLanguage),
|
||||||
case "embed":
|
"py": StreamLanguage.define(pythonLanguage),
|
||||||
case "data":
|
"protobuf": StreamLanguage.define(protobufLanguage),
|
||||||
return StreamLanguage.define(yamlLanguage);
|
"proto": StreamLanguage.define(protobufLanguage),
|
||||||
|
"shell": StreamLanguage.define(shellLanguage),
|
||||||
case "javascript":
|
"sh": StreamLanguage.define(shellLanguage),
|
||||||
case "js":
|
"bash": StreamLanguage.define(shellLanguage),
|
||||||
return javascriptLanguage;
|
"zsh": StreamLanguage.define(shellLanguage),
|
||||||
case "typescript":
|
"fish": StreamLanguage.define(shellLanguage),
|
||||||
case "ts":
|
"swift": StreamLanguage.define(rustLanguage),
|
||||||
return typescriptLanguage;
|
"toml": StreamLanguage.define(tomlLanguage),
|
||||||
case "sql":
|
"json": StreamLanguage.define(jsonLanguage),
|
||||||
return StreamLanguage.define(sqlLanguage);
|
"xml": StreamLanguage.define(xmlLanguage),
|
||||||
case "postgresql":
|
"c": StreamLanguage.define(cLanguage),
|
||||||
case "pgsql":
|
"cpp": StreamLanguage.define(cppLanguage),
|
||||||
case "postgres":
|
"c++": StreamLanguage.define(cppLanguage),
|
||||||
return StreamLanguage.define(postgresqlLanguage);
|
"cxx": StreamLanguage.define(cppLanguage),
|
||||||
case "rust":
|
"java": StreamLanguage.define(javaLanguage),
|
||||||
case "rs":
|
"csharp": StreamLanguage.define(csharpLanguage),
|
||||||
return StreamLanguage.define(rustLanguage);
|
"cs": StreamLanguage.define(csharpLanguage),
|
||||||
case "css":
|
"c#": StreamLanguage.define(csharpLanguage),
|
||||||
return StreamLanguage.define(sqlLanguage);
|
"scala": StreamLanguage.define(scalaLanguage),
|
||||||
case "html":
|
"kotlin": StreamLanguage.define(kotlinLanguage),
|
||||||
return htmlLanguage;
|
"objc": StreamLanguage.define(objectiveCLanguage),
|
||||||
case "python":
|
"objective-c": StreamLanguage.define(objectiveCLanguage),
|
||||||
case "py":
|
"objectivec": StreamLanguage.define(objectiveCLanguage),
|
||||||
return StreamLanguage.define(pythonLanguage);
|
"objcpp": StreamLanguage.define(objectiveCppLanguage),
|
||||||
case "protobuf":
|
"objective-cpp": StreamLanguage.define(objectiveCppLanguage),
|
||||||
case "proto":
|
"objectivecpp": StreamLanguage.define(objectiveCppLanguage),
|
||||||
return StreamLanguage.define(protobufLanguage);
|
"objective-c++": StreamLanguage.define(objectiveCppLanguage),
|
||||||
case "shell":
|
"objectivec++": StreamLanguage.define(objectiveCppLanguage),
|
||||||
case "sh":
|
"dart": StreamLanguage.define(dartLanguage),
|
||||||
case "bash":
|
"query": LRLanguage.define({
|
||||||
case "zsh":
|
|
||||||
case "fish":
|
|
||||||
return StreamLanguage.define(shellLanguage);
|
|
||||||
case "swift":
|
|
||||||
return StreamLanguage.define(rustLanguage);
|
|
||||||
case "toml":
|
|
||||||
return StreamLanguage.define(tomlLanguage);
|
|
||||||
case "json":
|
|
||||||
return StreamLanguage.define(jsonLanguage);
|
|
||||||
case "xml":
|
|
||||||
return StreamLanguage.define(xmlLanguage);
|
|
||||||
case "c":
|
|
||||||
return StreamLanguage.define(cLanguage);
|
|
||||||
case "cpp":
|
|
||||||
case "c++":
|
|
||||||
case "cxx":
|
|
||||||
return StreamLanguage.define(cppLanguage);
|
|
||||||
case "java":
|
|
||||||
return StreamLanguage.define(javaLanguage);
|
|
||||||
case "csharp":
|
|
||||||
case "cs":
|
|
||||||
case "c#":
|
|
||||||
return StreamLanguage.define(csharpLanguage);
|
|
||||||
case "scala":
|
|
||||||
return StreamLanguage.define(scalaLanguage);
|
|
||||||
case "kotlin":
|
|
||||||
return StreamLanguage.define(kotlinLanguage);
|
|
||||||
case "objc":
|
|
||||||
case "objective-c":
|
|
||||||
case "objectivec":
|
|
||||||
return StreamLanguage.define(objectiveCLanguage);
|
|
||||||
case "objcpp":
|
|
||||||
case "objective-cpp":
|
|
||||||
case "objectivecpp":
|
|
||||||
case "objective-c++":
|
|
||||||
case "objectivec++":
|
|
||||||
return StreamLanguage.define(objectiveCppLanguage);
|
|
||||||
|
|
||||||
case "dart":
|
|
||||||
return StreamLanguage.define(dartLanguage);
|
|
||||||
|
|
||||||
case "query":
|
|
||||||
return LRLanguage.define({
|
|
||||||
name: "query",
|
name: "query",
|
||||||
parser: highlightingDirectiveParser,
|
parser: highlightingDirectiveParser,
|
||||||
});
|
}),
|
||||||
|
};
|
||||||
|
|
||||||
default:
|
export function languageFor(name: string): Language | null {
|
||||||
|
if (builtinLanguages[name]) {
|
||||||
|
return builtinLanguages[name];
|
||||||
|
}
|
||||||
if (name.startsWith("#")) {
|
if (name.startsWith("#")) {
|
||||||
return StreamLanguage.define(yamlLanguage);
|
return StreamLanguage.define(yamlLanguage);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import { SysCallMapping } from "../../plugos/system.ts";
|
import { SysCallMapping } from "../../plugos/system.ts";
|
||||||
import { parse } from "../markdown_parser/parse_tree.ts";
|
import { parse } from "../markdown_parser/parse_tree.ts";
|
||||||
import type { ParseTree } from "$sb/lib/tree.ts";
|
import type { ParseTree } from "$sb/lib/tree.ts";
|
||||||
import { languageFor } from "../languages.ts";
|
import { builtinLanguages, languageFor } from "../languages.ts";
|
||||||
|
|
||||||
export function languageSyscalls(): SysCallMapping {
|
export function languageSyscalls(): SysCallMapping {
|
||||||
return {
|
return {
|
||||||
@ -16,5 +16,10 @@ export function languageSyscalls(): SysCallMapping {
|
|||||||
}
|
}
|
||||||
return parse(lang, code);
|
return parse(lang, code);
|
||||||
},
|
},
|
||||||
|
"language.listLanguages": (
|
||||||
|
_ctx,
|
||||||
|
): string[] => {
|
||||||
|
return Object.keys(builtinLanguages);
|
||||||
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -14,3 +14,7 @@ export function parseLanguage(
|
|||||||
): Promise<ParseTree> {
|
): Promise<ParseTree> {
|
||||||
return syscall("language.parseLanguage", language, code);
|
return syscall("language.parseLanguage", language, code);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function listLanguages(): Promise<string[]> {
|
||||||
|
return syscall("language.listLanguages");
|
||||||
|
}
|
||||||
|
@ -34,14 +34,3 @@ functions:
|
|||||||
path: command.ts:convertToLiveQuery
|
path: command.ts:convertToLiveQuery
|
||||||
command:
|
command:
|
||||||
name: "Directive: Convert Query to Live Query"
|
name: "Directive: Convert Query to Live Query"
|
||||||
|
|
||||||
# Templates
|
|
||||||
insertEvalTemplate:
|
|
||||||
redirect: template.insertTemplateText
|
|
||||||
slashCommand:
|
|
||||||
name: eval
|
|
||||||
description: Evaluate a JavaScript expression
|
|
||||||
value: |
|
|
||||||
<!-- #eval |^| -->
|
|
||||||
|
|
||||||
<!-- /eval -->
|
|
@ -1,5 +1,5 @@
|
|||||||
import { CompleteEvent } from "$sb/app_event.ts";
|
import { CompleteEvent } from "$sb/app_event.ts";
|
||||||
import { events } from "$sb/syscalls.ts";
|
import { events, language } from "$sb/syscalls.ts";
|
||||||
import {
|
import {
|
||||||
AttributeCompleteEvent,
|
AttributeCompleteEvent,
|
||||||
AttributeCompletion,
|
AttributeCompletion,
|
||||||
@ -7,11 +7,12 @@ import {
|
|||||||
|
|
||||||
export async function queryComplete(completeEvent: CompleteEvent) {
|
export async function queryComplete(completeEvent: CompleteEvent) {
|
||||||
const fencedParent = completeEvent.parentNodes.find((node) =>
|
const fencedParent = completeEvent.parentNodes.find((node) =>
|
||||||
node === "FencedCode:query"
|
node.startsWith("FencedCode:query")
|
||||||
);
|
);
|
||||||
if (!fencedParent) {
|
if (!fencedParent) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
// First let's try to match the query source
|
||||||
let querySourceMatch = /^\s*([\w\-_]*)$/.exec(
|
let querySourceMatch = /^\s*([\w\-_]*)$/.exec(
|
||||||
completeEvent.linePrefix,
|
completeEvent.linePrefix,
|
||||||
);
|
);
|
||||||
@ -41,8 +42,10 @@ export async function queryComplete(completeEvent: CompleteEvent) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
querySourceMatch = /^\s*([\w\-_]*)/.exec(
|
// If that doesn't work, let's try to match other bits of the query
|
||||||
completeEvent.linePrefix,
|
// For this we do need to find the query source, though, so let's look for it in fencedParent
|
||||||
|
querySourceMatch = /^[\n\r\s]*([\w\-_]+)/.exec(
|
||||||
|
fencedParent.slice("FencedCode:query".length),
|
||||||
);
|
);
|
||||||
const whereMatch =
|
const whereMatch =
|
||||||
/(where|order\s+by|and|or|select(\s+[\w\s,]+)?)\s+([\w\-_]*)$/
|
/(where|order\s+by|and|or|select(\s+[\w\s,]+)?)\s+([\w\-_]*)$/
|
||||||
@ -78,3 +81,23 @@ function attributeCompletionsToCMCompletion(
|
|||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function languageComplete(completeEvent: CompleteEvent) {
|
||||||
|
const languagePrefix = /^```(\w*)$/.exec(
|
||||||
|
completeEvent.linePrefix,
|
||||||
|
);
|
||||||
|
if (!languagePrefix) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
const allLanguages = await language.listLanguages();
|
||||||
|
return {
|
||||||
|
from: completeEvent.pos - languagePrefix[1].length,
|
||||||
|
options: allLanguages.map(
|
||||||
|
(lang) => ({
|
||||||
|
label: lang,
|
||||||
|
type: "language",
|
||||||
|
}),
|
||||||
|
),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
@ -15,6 +15,11 @@ functions:
|
|||||||
events:
|
events:
|
||||||
- editor:complete
|
- editor:complete
|
||||||
|
|
||||||
|
languageComplete:
|
||||||
|
path: complete.ts:languageComplete
|
||||||
|
events:
|
||||||
|
- editor:complete
|
||||||
|
|
||||||
# Slash commands
|
# Slash commands
|
||||||
insertQuery:
|
insertQuery:
|
||||||
redirect: template.insertTemplateText
|
redirect: template.insertTemplateText
|
||||||
|
@ -46,10 +46,10 @@ functions:
|
|||||||
redirect: insertTemplateText
|
redirect: insertTemplateText
|
||||||
slashCommand:
|
slashCommand:
|
||||||
name: code
|
name: code
|
||||||
description: Insert code block
|
description: Insert fenced code block
|
||||||
value: |
|
value: |
|
||||||
```
|
```|^|
|
||||||
|^|
|
|
||||||
```
|
```
|
||||||
|
|
||||||
insertHRTemplate:
|
insertHRTemplate:
|
||||||
|
@ -640,9 +640,8 @@ export class Client {
|
|||||||
let node: SyntaxNode | null = currentNode;
|
let node: SyntaxNode | null = currentNode;
|
||||||
do {
|
do {
|
||||||
if (node.name === "FencedCode") {
|
if (node.name === "FencedCode") {
|
||||||
const code = editorState.sliceDoc(node.from + 3, node.to);
|
const body = editorState.sliceDoc(node.from + 3, node.to - 3);
|
||||||
const fencedCodeLanguage = code.split("\n")[0];
|
parentNodes.push(`FencedCode:${body}`);
|
||||||
parentNodes.push(`FencedCode:${fencedCodeLanguage}`);
|
|
||||||
} else {
|
} else {
|
||||||
parentNodes.push(node.name);
|
parentNodes.push(node.name);
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,15 @@ release.
|
|||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
## Next
|
||||||
|
* Fixes to auto-sizing of [[Live Queries]] and [[Live Templates]] widgets
|
||||||
|
* Fixed the combination of `limit` and `order by` not working well
|
||||||
|
* Auto complete for queries now works for queries split across multiple lines
|
||||||
|
* Auto complete for fenced code block languages (use the `/code` slash command)
|
||||||
|
* Slightly tweaked semantics for the `=` operator on arrays, see [[Live Queries]] for details
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
## 0.5.0
|
## 0.5.0
|
||||||
Oh boy, this is a big one. This release brings you the following:
|
Oh boy, this is a big one. This release brings you the following:
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user