Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/ai-native/src/browser/components/ChatMarkdown.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import cls from 'classnames';
import React, { ReactNode, useEffect, useRef, useState } from 'react';
import React, { useEffect, useRef, useState } from 'react';

import { MarkdownReactParser, MarkdownReactRenderer } from '@opensumi/ide-components/lib/markdown-react';
import { IMarkedOptions, marked } from '@opensumi/ide-components/lib/utils';
Expand Down
2 changes: 1 addition & 1 deletion packages/ai-native/src/browser/components/WelcomeMsg.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
import { isMarkdownString } from '@opensumi/monaco-editor-core/esm/vs/base/common/htmlContent';

import 'react-chat-elements/dist/main.css';
import { IChatAgentService, IChatReplyFollowup, ISampleQuestions } from '../../common';
import { IChatAgentService, ISampleQuestions } from '../../common';
import { ChatService } from '../chat/chat.api.service';
import { ChatFeatureRegistry } from '../chat/chat.feature.registry';
import { ChatRenderRegistry } from '../chat/chat.render.registry';
Expand Down
2 changes: 1 addition & 1 deletion packages/components/src/icon/iconfont/iconManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class IconManager {
const iconValue = this._iconMap[this._ktIconPrefixes[lastIndex]][iconKey];

if (!iconValue) {
warning(false, '图标库缺失图标:' + iconKey);
warning(false, 'No icon found for ' + iconKey);
return [];
}
return [`${this._ktIconPrefixes[lastIndex]}${iconValue}`];
Expand Down
192 changes: 107 additions & 85 deletions packages/components/src/markdown-react/parse.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { marked } from 'marked';
import { ReactNode } from 'react';
import React, { ReactNode } from 'react';

import { HeadingLevels, MarkdownReactRenderer } from './render';

Expand All @@ -16,93 +16,115 @@ export class MarkdownReactParser extends marked.Renderer {
}

parse(tokens: marked.Token[]): ReactNode[] {
return tokens.map((token) => {
switch (token.type) {
case 'html': {
return this.renderer.html(token.text);
}

case 'space': {
return null;
}

case 'heading': {
const level = token.depth as HeadingLevels;
return this.renderer.heading(this.parseInline(token.tokens), level);
}

case 'paragraph': {
return this.renderer.paragraph(this.parseInline(token.tokens));
}

case 'text': {
const textToken = token as marked.Tokens.Text;
return textToken.tokens ? this.parseInline(textToken.tokens) : token.text;
}

case 'blockquote': {
const blockquoteToken = token as marked.Tokens.Blockquote;
const quote = this.parse(blockquoteToken.tokens);
return this.renderer.blockquote(quote);
}

case 'list': {
const listToken = token as marked.Tokens.List;

const children = listToken.items.map((item) => {
const listItemChildren: ReactNode[] = [];

if (item.task) {
listItemChildren.push(this.renderer.checkbox(item.checked ?? false));
}

listItemChildren.push(this.parse(item.tokens));

return this.renderer.listItem(listItemChildren);
});

return this.renderer.list(children, token.ordered);
}

case 'code': {
return this.renderer.code(token.text, token.lang);
}

case 'table': {
const tableToken = token as marked.Tokens.Table;
const headerCells = tableToken.header.map((cell, index) =>
this.renderer.tableCell(this.parseInline(cell.tokens), { header: true, align: token.align[index] }),
);

const headerRow = this.renderer.tableRow(headerCells);
const header = this.renderer.tableHeader(headerRow);

const bodyChilren = tableToken.rows.map((row) => {
const rowChildren = row.map((cell, index) =>
this.renderer.tableCell(this.parseInline(cell.tokens), {
header: false,
align: token.align[index],
}),
return tokens.map((token, index) => {
const element = (() => {
switch (token.type) {
case 'html': {
return this.renderer.html(token.text);
}

case 'space': {
return null;
}

case 'heading': {
const level = token.depth as HeadingLevels;
return this.renderer.heading(this.parseInline(token.tokens), level);
}

case 'paragraph': {
return this.renderer.paragraph(this.parseInline(token.tokens));
}

case 'text': {
const textToken = token as marked.Tokens.Text;
return textToken.tokens ? this.parseInline(textToken.tokens) : token.text;
}

case 'blockquote': {
const blockquoteToken = token as marked.Tokens.Blockquote;
const quote = this.parse(blockquoteToken.tokens);
return this.renderer.blockquote(quote);
}

case 'list': {
const listToken = token as marked.Tokens.List;

const children = listToken.items.map((item, itemIndex) => {
const listItemChildren: ReactNode[] = [];

if (item.task) {
listItemChildren.push(this.renderer.checkbox(item.checked ?? false));
}

listItemChildren.push(this.parse(item.tokens));

return React.cloneElement(this.renderer.listItem(listItemChildren) as React.ReactElement, {
key: `list-item-${itemIndex}`,
});
});

return this.renderer.list(children, token.ordered);
}

case 'code': {
return this.renderer.code(token.text, token.lang);
}

case 'table': {
const tableToken = token as marked.Tokens.Table;
const headerCells = tableToken.header.map((cell, cellIndex) =>
React.cloneElement(
this.renderer.tableCell(this.parseInline(cell.tokens), {
header: true,
align: token.align[cellIndex],
}) as React.ReactElement,
{ key: `header-cell-${cellIndex}` },
),
);

return this.renderer.tableRow(rowChildren);
});

const body = this.renderer.tableBody(bodyChilren);

return this.renderer.table([header, body]);
}

case 'hr': {
return this.renderer.hr();
}

default: {
// eslint-disable-next-line no-console
console.warn(`Token with "${token.type}" type was not found`);
return null;
}
const headerRow = React.cloneElement(this.renderer.tableRow(headerCells) as React.ReactElement, {
key: 'header-row',
});
const header = this.renderer.tableHeader(headerRow);

const bodyChilren = tableToken.rows.map((row, rowIndex) => {
const rowChildren = row.map((cell, cellIndex) =>
React.cloneElement(
this.renderer.tableCell(this.parseInline(cell.tokens), {
header: false,
align: token.align[cellIndex],
}) as React.ReactElement,
{ key: `body-cell-${rowIndex}-${cellIndex}` },
),
);

return React.cloneElement(this.renderer.tableRow(rowChildren) as React.ReactElement, {
key: `body-row-${rowIndex}`,
});
});

const body = this.renderer.tableBody(bodyChilren);

return this.renderer.table([header, body]);
}

case 'hr': {
return this.renderer.hr();
}

default: {
// eslint-disable-next-line no-console
console.warn(`Token with "${token.type}" type was not found`);
return null;
}
}
})();

if (React.isValidElement(element)) {
return React.cloneElement(element, { key: `token-${index}` });
}
return element;
});
}

Expand Down
2 changes: 1 addition & 1 deletion packages/components/src/utils/warning.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export function warning(valid: boolean, message: string) {
// Support uglify
if (process.env.NODE_ENV !== 'production' && !valid && console !== undefined) {
// eslint-disable-next-line no-console
console.error(`Warning: ${message}`);
console.warn(`Warning: ${message}`);
}
}

Expand Down
6 changes: 6 additions & 0 deletions packages/connection/src/common/rpc/connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,12 @@ export class SumiConnection implements IDisposable {
const opType = message.kind;
const requestId = message.requestId;

if (opType === OperationType.Error) {
this.logger.warn(
`[${message.requestId}] Error received from server method ${message.method}: ${message.error}`,
);
}

switch (opType) {
case OperationType.Error:
case OperationType.Response: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,6 @@ export function getCDNHref(
}
}

export function getTreeSitterWasmCDNUri(CDNType: string = 'alipay') {
export function getTreeSitterWasmCDNUri(CDNType: string = 'npmmirror') {
return getCDNHref('@opensumi/tree-sitter-wasm', '', '0.0.2', CDNType as TComponentCDNType);
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ export class FileTreeAPI implements IFileTreeAPI {

@Autowired(IDialogService)
private readonly dialogService: IDialogService;
private cacheFileStat: Map<string, FileStat> = new Map();

private userhomePath: URI;

Expand Down
3 changes: 2 additions & 1 deletion packages/terminal-next/src/browser/component/resize.view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ export interface IResizeViewProps {

const ResizeItem = ({ index, widget, wholeWidth, setEvent, self, left, right, last }) => {
const shadowDynamic = useAutorun(widget.shadowDynamic);

return (
<div key={`resize-item-${index}`} style={{ width: `${shadowDynamic}%` }} className={styles.resizeHandler}>
<ResizeDelegate
Expand Down Expand Up @@ -88,6 +87,7 @@ export default (props: IResizeViewProps) => {

return (
<ResizeItem
key={index}
index={index}
widget={widget}
wholeWidth={wholeWidth}
Expand All @@ -104,6 +104,7 @@ export default (props: IResizeViewProps) => {
{widgets &&
widgets.map((widget) => (
<ResizePanelItem
key={widget.id}
widget={widget}
dynamic={shadow ? widget.dynamic : widget.shadowDynamic}
draw={props.draw}
Expand Down