Skip to content

Commit fc85d27

Browse files
authored
fix filtering and snippets for blockAliasFor in monaco (#11035)
1 parent a75bfde commit fc85d27

File tree

5 files changed

+12
-3
lines changed

5 files changed

+12
-3
lines changed

pxtcompiler/emitter/languageservice.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -607,6 +607,7 @@ namespace ts.pxtc.service {
607607
blocksInfo,
608608
screenSize,
609609
apis: lastApiInfo.apis,
610+
decls: lastApiInfo.decls,
610611
checker: service?.getProgram()?.getTypeChecker()
611612
}
612613
resultSymbols.forEach(sym => patchSymbolWithSnippet(sym.symbol, isPython, context))

pxtcompiler/emitter/service.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1025,7 +1025,7 @@ namespace ts.pxtc.service {
10251025
}
10261026

10271027
const { bannedCategories, screenSize } = v.runtime;
1028-
const { apis } = lastApiInfo;
1028+
const { apis, decls } = lastApiInfo;
10291029
const blocksInfo = blocksInfoOp(apis, bannedCategories);
10301030
const checker = service && service.getProgram().getTypeChecker();
10311031
// needed for blocks that have parent wraps like music.play(...)
@@ -1039,7 +1039,8 @@ namespace ts.pxtc.service {
10391039
bannedCategories,
10401040
screenSize,
10411041
checker,
1042-
includeParentSnippet
1042+
includeParentSnippet,
1043+
decls
10431044
}
10441045
const snippetNode = getSnippet(snippetContext, fn, n as FunctionLikeDeclaration, isPython)
10451046
const snippet = snippetStringify(snippetNode)

pxtcompiler/emitter/snippets.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ namespace ts.pxtc.service {
106106
screenSize?: pxt.Size;
107107
parameterOverride?: { [key: string]: SnippetNode };
108108
includeParentSnippet?: boolean;
109+
decls?: pxt.Map<ts.Declaration>;
109110
}
110111

111112
export function getSnippet(context: SnippetContext, fn: SymbolInfo, decl: ts.FunctionLikeDeclaration, python?: boolean, recursionDepth = 0): SnippetNode {
@@ -116,6 +117,11 @@ namespace ts.pxtc.service {
116117
const PY_INDENT: string = (pxt as any).py.INDENT;
117118
const fileType = python ? "python" : "typescript";
118119

120+
if (fn.attributes.blockAliasFor) {
121+
fn = apis.byQName[fn.attributes.blockAliasFor] || fn;
122+
decl = context.decls?.[fn.qName] as ts.FunctionLikeDeclaration || decl;
123+
}
124+
119125
let snippetPrefix = fn.namespace;
120126
let addNamespace = false;
121127
let namespaceToUse = "";

webapp/src/monaco.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2007,7 +2007,7 @@ export class Editor extends toolboxeditor.ToolboxEditor {
20072007
private filterBlocks(subns: string, blocks: toolbox.BlockDefinition[]) {
20082008
return blocks.filter((block => !(block.attributes.blockHidden)
20092009
&& !(block.attributes.deprecated && !this.parent.isTutorial())
2010-
&& (block.name.indexOf('_') != 0)
2010+
&& (block.name.indexOf('_') != 0 || block.attributes.blockAliasFor)
20112011
&& ((!subns && !block.attributes.subcategory && !block.attributes.advanced)
20122012
|| (subns && ((block.attributes.advanced && subns == lf("more"))
20132013
|| (block.attributes.subcategory && subns == block.attributes.subcategory))))));

webapp/src/toolbox.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ export interface BlockDefinition {
5656
_def?: pxtc.ParsedBlockDef;
5757
parentBlock?: BlockDefinition;
5858
toolboxParentArgument?: string;
59+
blockAliasFor?: string;
5960
};
6061
retType?: string;
6162
blockXml?: string;

0 commit comments

Comments
 (0)