Skip to content

Commit

Permalink
start on #174079
Browse files Browse the repository at this point in the history
  • Loading branch information
meganrogge committed Feb 28, 2023
1 parent 02a84ef commit b5dd32b
Showing 1 changed file with 14 additions and 22 deletions.
36 changes: 14 additions & 22 deletions src/vs/workbench/contrib/terminal/browser/xterm/xtermTerminal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,15 @@ import { IContextKey } from 'vs/platform/contextkey/common/contextkey';
import { URI } from 'vs/base/common/uri';
import { ITextModel } from 'vs/editor/common/model';
import { IModelService } from 'vs/editor/common/services/model';
import { StringBuilder } from 'vs/editor/common/core/stringBuilder';
import { CodeEditorWidget, ICodeEditorWidgetOptions } from 'vs/editor/browser/widget/codeEditorWidget';
import { EditorExtensionsRegistry } from 'vs/editor/browser/editorExtensions';
import { getSimpleEditorOptions } from 'vs/workbench/contrib/codeEditor/browser/simpleEditorOptions';
import { IEditorConstructionOptions } from 'vs/editor/browser/config/editorConfiguration';
import { LinkDetector } from 'vs/editor/contrib/links/browser/links';
import { SelectionClipboardContributionID } from 'vs/workbench/contrib/codeEditor/browser/selectionClipboard';
import { ILanguageFeaturesService } from 'vs/editor/common/services/languageFeatures';
import { CancellationToken } from 'vs/base/common/cancellation';
import { DocumentSymbol } from 'vs/editor/common/languages';

const enum RenderConstants {
/**
Expand Down Expand Up @@ -791,7 +793,8 @@ class AccessibleBuffer extends DisposableStore {
private readonly _capabilities: ITerminalCapabilityStore,
@IInstantiationService private readonly _instantiationService: IInstantiationService,
@IModelService private readonly _modelService: IModelService,
@IConfigurationService configurationService: IConfigurationService
@IConfigurationService configurationService: IConfigurationService,
@ILanguageFeaturesService private readonly _languageFeaturesService: ILanguageFeaturesService
) {
super();
const codeEditorWidgetOptions: ICodeEditorWidgetOptions = {
Expand Down Expand Up @@ -827,6 +830,12 @@ class AccessibleBuffer extends DisposableStore {
this._font = this._terminal.getFont();
}
}));
this._languageFeaturesService.documentSymbolProvider.register('Terminal', {
provideDocumentSymbols: (model: ITextModel, token: CancellationToken): Promise<DocumentSymbol[] | undefined> => {
console.log(model);
return Promise.resolve([{ name: 'test', detail: 'none', kind: 0, tags: [], range: { startLineNumber: 0, endLineNumber: 0, startColumn: 0, endColumn: 5 }, selectionRange: { startLineNumber: 0, endLineNumber: 0, startColumn: 0, endColumn: 5 } }]);
}
});
}

async focus(): Promise<void> {
Expand All @@ -835,7 +844,7 @@ class AccessibleBuffer extends DisposableStore {

private async _updateBufferEditor(): Promise<void> {
const commandDetection = this._capabilities.get(TerminalCapability.CommandDetection);
const fragment = !!commandDetection ? this._getShellIntegrationContent() : this._getAllContent();
const fragment = this._getBufferContent();
const model = await this._getTextModel(URI.from({ scheme: AccessibleBufferConstants.Scheme, fragment }));
if (model) {
this._bufferEditor.setModel(model);
Expand Down Expand Up @@ -877,28 +886,11 @@ class AccessibleBuffer extends DisposableStore {
if (existing && !existing.isDisposed()) {
return existing;
}

existing?.setLanguage('terminal');
return this._modelService.createModel(resource.fragment, null, resource, false);
}

private _getShellIntegrationContent(): string {
const commands = this._capabilities.get(TerminalCapability.CommandDetection)?.commands;
const sb = new StringBuilder(10000);
if (!commands?.length) {
return this._getAllContent();
}
for (const command of commands) {
sb.appendString(command.command.replace(new RegExp(' ', 'g'), '\xA0'));
if (command.exitCode !== 0) {
sb.appendString(` exited with code ${command.exitCode}`);
}
sb.appendString('\n');
sb.appendString(command.getOutput()?.replace(new RegExp(' ', 'g'), '\xA0') || '');
}
return sb.build();
}

private _getAllContent(): string {
private _getBufferContent(): string {
const lines: string[] = [];
let currentLine: string = '';
const buffer = this._terminal.raw.buffer.active;
Expand Down

0 comments on commit b5dd32b

Please sign in to comment.