Skip to content
This repository has been archived by the owner on Dec 13, 2018. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
hansonw committed Mar 5, 2018
2 parents cece913 + 5ed2766 commit a32f49c
Show file tree
Hide file tree
Showing 22 changed files with 741 additions and 160 deletions.
5 changes: 4 additions & 1 deletion flow-libs/atom.js.flow
Original file line number Diff line number Diff line change
Expand Up @@ -1028,7 +1028,7 @@ declare class atom$TextEditor extends atom$Model {
onDidConflict(callback: () => void): IDisposable,
serialize(): Object,
foldBufferRowRange(startRow: number, endRow: number): void,
getNonWordCharacters(scope?: atom$ScopeDescriptor): string,
getNonWordCharacters(position?: atom$PointLike): string,
}

/**
Expand Down Expand Up @@ -2049,6 +2049,9 @@ type atom$AutocompleteProvider = {
+getSuggestions: (
request: atom$AutocompleteRequest,
) => Promise<?Array<atom$AutocompleteSuggestion>> | ?Array<atom$AutocompleteSuggestion>,
+getSuggestionDetailsOnSelect?: (
suggestion: atom$AutocompleteSuggestion
) => Promise<?atom$AutocompleteSuggestion>,
+disableForSelector?: string,
+inclusionPriority?: number,
+excludeLowerPriority?: boolean,
Expand Down
4 changes: 4 additions & 0 deletions flow-libs/vscode-debugprotocol.js.flow
Original file line number Diff line number Diff line change
Expand Up @@ -1075,6 +1075,10 @@ declare module 'vscode-debugprotocol' {
supportsExceptionInfoRequest?: boolean,
/** The debug adapter supports the 'terminateDebuggee' attribute on the 'disconnect' request. */
supportTerminateDebuggee?: boolean,
/** The debug adapter supports custom `continueToLocation` logic.
* This is not part of the standard Visual Studio Code debug protocol.
*/
supportsContinueToLocation?: boolean,
};

/** An ExceptionBreakpointsFilter is shown in the UI as an option for configuring how exceptions are dealt with. */
Expand Down
10 changes: 9 additions & 1 deletion modules/atom-ide-ui/pkg/atom-ide-console/lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,9 @@ class Activation {
info(object: string): void {
console.append({text: object, level: 'info'});
},
success(object: string): void {
console.append({text: object, level: 'success'});
},
append(message: Message): void {
invariant(activation != null && !disposed);
activation._getStore().dispatch(
Expand Down Expand Up @@ -328,7 +331,12 @@ class Activation {
records: this._store
.getState()
.records.slice(-maximumSerializedMessages)
.toArray(),
.toArray()
.map(record => {
// `Executor` is not serializable. Make sure to remove it first.
const {executor, ...rest} = record;
return rest;
}),
history: this._store.getState().history.slice(-maximumSerializedHistory),
};
}
Expand Down
111 changes: 111 additions & 0 deletions modules/atom-ide-ui/pkg/atom-ide-console/lib/parseText.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
/**
* Copyright (c) 2017-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
* @flow
* @format
*/

import {goToLocation} from 'nuclide-commons-atom/go-to-location';
import * as React from 'react';
import featureConfig from 'nuclide-commons-atom/feature-config';

import {URL_REGEX} from 'nuclide-commons/string';
const DIFF_PATTERN = '\\b[dD][1-9][0-9]{5,}\\b';
const TASK_PATTERN = '\\b[tT]\\d+\\b';
const FILE_PATH_PATTERN =
'([/A-Za-z_-s0-9.-]+[.][A-Za-z]+)(:([0-9]+))?(:([0-9]+))?';
const CLICKABLE_PATTERNS = `(${DIFF_PATTERN})|(${TASK_PATTERN})|(${
URL_REGEX.source
})|${FILE_PATH_PATTERN}`;
const CLICKABLE_RE = new RegExp(CLICKABLE_PATTERNS, 'g');

function toString(value: mixed): string {
return typeof value === 'string' ? value : '';
}

/**
* Parse special entities into links. In the future, it would be great to add a service so that we
* could add new clickable things and to allow providers to mark specific ranges as links to things
* that only they can know (e.g. relative paths output in BUCK messages). For now, however, we'll
* just use some pattern settings and hardcode the patterns we care about.
*/
export default function parseText(
text: string,
): Array<string | React.Element<any>> {
const chunks = [];
let lastIndex = 0;
let index = 0;
while (true) {
const match = CLICKABLE_RE.exec(text);
if (match == null) {
break;
}

const matchedText = match[0];

// Add all the text since our last match.
chunks.push(
text.slice(lastIndex, CLICKABLE_RE.lastIndex - matchedText.length),
);
lastIndex = CLICKABLE_RE.lastIndex;

let href;
let handleOnClick;
if (match[1] != null) {
// It's a diff
const url = toString(
featureConfig.get('atom-ide-console.diffUrlPattern'),
);
if (url !== '') {
href = url.replace('%s', matchedText);
}
} else if (match[2] != null) {
// It's a task
const url = toString(
featureConfig.get('atom-ide-console.taskUrlPattern'),
);
if (url !== '') {
href = url.replace('%s', matchedText.slice(1));
}
} else if (match[3] != null) {
// It's a URL
href = matchedText;
} else if (match[5] != null) {
// It's a file path
href = '#';
handleOnClick = () => {
goToLocation(match[5], {
line: match[7] ? parseInt(match[7], 10) - 1 : 0,
column: match[9] ? parseInt(match[9], 10) - 1 : 0,
});
};
}

chunks.push(
// flowlint-next-line sketchy-null-string:off
href ? (
<a
key={`r${index}`}
href={href}
target="_blank"
onClick={handleOnClick}>
{matchedText}
</a>
) : (
matchedText
),
);

index++;
}

// Add any remaining text.
chunks.push(text.slice(lastIndex));

return chunks;
}
1 change: 1 addition & 0 deletions modules/atom-ide-ui/pkg/atom-ide-console/lib/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export type ConsoleApi = {
error(object: string, _: void): void,
warn(object: string, _: void): void,
info(object: string, _: void): void,
success(object: string, _: void): void,

// A generic API for sending a message of any level (log, error, etc.).
append(message: Message): void,
Expand Down
80 changes: 1 addition & 79 deletions modules/atom-ide-ui/pkg/atom-ide-console/lib/ui/RecordView.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ import shallowEqual from 'shallowequal';
import {TextRenderer} from 'nuclide-commons-ui/TextRenderer';
import debounce from 'nuclide-commons/debounce';
import {nextAnimationFrame} from 'nuclide-commons/observable';
import {URL_REGEX} from 'nuclide-commons/string';
import featureConfig from 'nuclide-commons-atom/feature-config';
import parseText from '../parseText';

type Props = {
displayableRecord: DisplayableRecord,
Expand Down Expand Up @@ -238,80 +237,3 @@ function getIconName(record: Record): ?string {
return 'stop';
}
}

/**
* Parse special entities into links. In the future, it would be great to add a service so that we
* could add new clickable things and to allow providers to mark specific ranges as links to things
* that only they can know (e.g. relative paths output in BUCK messages). For now, however, we'll
* just use some pattern settings and hardcode the patterns we care about.
*/
function parseText(text: string): Array<string | React.Element<any>> {
const chunks = [];
let lastIndex = 0;
let index = 0;
while (true) {
const match = CLICKABLE_RE.exec(text);
if (match == null) {
break;
}

const matchedText = match[0];

// Add all the text since our last match.
chunks.push(
text.slice(lastIndex, CLICKABLE_RE.lastIndex - matchedText.length),
);
lastIndex = CLICKABLE_RE.lastIndex;

let href;
if (match[1] != null) {
// It's a diff
const url = toString(
featureConfig.get('atom-ide-console.diffUrlPattern'),
);
if (url !== '') {
href = url.replace('%s', matchedText);
}
} else if (match[2] != null) {
// It's a task
const url = toString(
featureConfig.get('atom-ide-console.taskUrlPattern'),
);
if (url !== '') {
href = url.replace('%s', matchedText.slice(1));
}
} else if (match[3] != null) {
// It's a URL
href = matchedText;
}

chunks.push(
// flowlint-next-line sketchy-null-string:off
href ? (
<a key={`r${index}`} href={href} target="_blank">
{matchedText}
</a>
) : (
matchedText
),
);

index++;
}

// Add any remaining text.
chunks.push(text.slice(lastIndex));

return chunks;
}

const DIFF_PATTERN = '\\b[dD][1-9][0-9]{5,}\\b';
const TASK_PATTERN = '\\b[tT]\\d+\\b';
const CLICKABLE_PATTERNS = `(${DIFF_PATTERN})|(${TASK_PATTERN})|${
URL_REGEX.source
}`;
const CLICKABLE_RE = new RegExp(CLICKABLE_PATTERNS, 'g');

function toString(value: mixed): string {
return typeof value === 'string' ? value : '';
}
Loading

0 comments on commit a32f49c

Please sign in to comment.