Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

On Type Rename for #88424 #92597

Merged
merged 24 commits into from
Mar 18, 2020
Merged
Show file tree
Hide file tree
Changes from 16 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
13 changes: 13 additions & 0 deletions extensions/html-language-features/client/src/htmlMain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ namespace TagCloseRequest {
namespace MatchingTagPositionRequest {
export const type: RequestType<TextDocumentPositionParams, Position | null, any, any> = new RequestType('html/matchingTagPosition');
}
namespace SyncedRegionsRequest {
export const type: RequestType<TextDocumentPositionParams, Range[] | null, any, any> = new RequestType('html/syncedRegions');
}

// experimental: semantic tokens
interface SemanticTokenParams {
Expand Down Expand Up @@ -289,6 +292,16 @@ export function activate(context: ExtensionContext) {
return results;
}
});

// TODO
languages.registerOnTypeRenameProvider(documentSelector, {
async provideOnTypeRenameRanges(document, position) {
const param = client.code2ProtocolConverter.asTextDocumentPositionParams(document, position);
const response = await client.sendRequest(SyncedRegionsRequest.type, param);

return response || [];
}
});
}

function getPackageInfo(context: ExtensionContext): IPackageInfo | null {
Expand Down
19 changes: 19 additions & 0 deletions extensions/html-language-features/server/src/htmlServerMain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ namespace TagCloseRequest {
namespace MatchingTagPositionRequest {
export const type: RequestType<TextDocumentPositionParams, Position | null, any, any> = new RequestType('html/matchingTagPosition');
}
namespace SyncedRegionsRequest {
export const type: RequestType<TextDocumentPositionParams, Range[] | null, any, any> = new RequestType('html/syncedRegions');
}

// experimental: semantic tokens
interface SemanticTokenParams {
Expand Down Expand Up @@ -515,6 +518,22 @@ connection.onRequest(MatchingTagPositionRequest.type, (params, token) => {
}, null, `Error while computing matching tag position for ${params.textDocument.uri}`, token);
});

connection.onRequest(SyncedRegionsRequest.type, (params, token) => {
return runSafe(() => {
const document = documents.get(params.textDocument.uri);
if (document) {
const pos = params.position;
if (pos.character > 0) {
const mode = languageModes.getModeAtPosition(document, Position.create(pos.line, pos.character - 1));
if (mode && mode.findSyncedRegions) {
return mode.findSyncedRegions(document, pos);
}
}
}
return null;
}, null, `Error while computing synced regions for ${params.textDocument.uri}`, token);
});

let semanticTokensProvider: SemanticTokenProvider | undefined;
function getSemanticTokenProvider() {
if (!semanticTokensProvider) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ export function getHTMLMode(htmlLanguageService: HTMLLanguageService, workspace:
const htmlDocument = htmlDocuments.get(document);
return htmlLanguageService.findMatchingTagPosition(document, position, htmlDocument);
},
findSyncedRegions(document: TextDocument, position: Position) {
const htmlDocument = htmlDocuments.get(document);
return htmlLanguageService.findSyncedRegions(document, position, htmlDocument);
},
dispose() {
htmlDocuments.dispose();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ export interface LanguageMode {
getColorPresentations?: (document: TextDocument, color: Color, range: Range) => ColorPresentation[];
doAutoClose?: (document: TextDocument, position: Position) => string | null;
findMatchingTagPosition?: (document: TextDocument, position: Position) => Position | null;
findSyncedRegions?: (document: TextDocument, position: Position) => Range[] | null;
getFoldingRanges?: (document: TextDocument) => FoldingRange[];
onDocumentRemoved(document: TextDocument): void;
getSemanticTokens?(document: TextDocument): SemanticTokenData[];
Expand Down
10 changes: 10 additions & 0 deletions src/vs/editor/common/config/editorOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,11 @@ export interface IEditorOptions {
* Defaults to false.
*/
automaticLayout?: boolean;
/**
* Rename matching regions on type.
* Defaults to false.
*/
renameOnType?: boolean;
/**
* Control the wrapping of the editor.
* When `wordWrap` = "off", the lines will never wrap.
Expand Down Expand Up @@ -3311,6 +3316,7 @@ export const enum EditorOption {
autoClosingQuotes,
autoIndent,
automaticLayout,
renameOnType,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like to keep these sorted alphabetically, please move it down a bit.

autoSurround,
codeLens,
colorDecorators,
Expand Down Expand Up @@ -3518,6 +3524,10 @@ export const EditorOptions = {
automaticLayout: register(new EditorBooleanOption(
EditorOption.automaticLayout, 'automaticLayout', false,
)),
renameOnType: register(new EditorBooleanOption(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also here, please move it down a bit.

EditorOption.renameOnType, 'renameOnType', false,
{ description: nls.localize('renameOnType', "Controls whether the editor auto renames on type.") }
)),
autoSurround: register(new EditorStringEnumOption(
EditorOption.autoSurround, 'autoSurround',
'languageDefined' as 'languageDefined' | 'quotes' | 'brackets' | 'never',
Expand Down
19 changes: 19 additions & 0 deletions src/vs/editor/common/modes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -789,6 +789,20 @@ export interface DocumentHighlightProvider {
provideDocumentHighlights(model: model.ITextModel, position: Position, token: CancellationToken): ProviderResult<DocumentHighlight[]>;
}

/**
* The rename provider interface defines the contract between extensions and
* the live-rename feature.
*/
export interface OnTypeRenameProvider {

stopPattern?: RegExp;

/**
* Provide a list of ranges that can be live-renamed together.
*/
provideOnTypeRenameRanges(model: model.ITextModel, position: Position, token: CancellationToken): ProviderResult<IRange[]>;
}

/**
* Value-object that contains additional information when
* requesting references.
Expand Down Expand Up @@ -1642,6 +1656,11 @@ export const DocumentSymbolProviderRegistry = new LanguageFeatureRegistry<Docume
*/
export const DocumentHighlightProviderRegistry = new LanguageFeatureRegistry<DocumentHighlightProvider>();

/**
* @internal
*/
export const OnTypeRenameProviderRegistry = new LanguageFeatureRegistry<OnTypeRenameProvider>();

/**
* @internal
*/
Expand Down
209 changes: 105 additions & 104 deletions src/vs/editor/common/standalone/standaloneEnums.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,110 +175,111 @@ export enum EditorOption {
autoClosingQuotes = 7,
autoIndent = 8,
automaticLayout = 9,
autoSurround = 10,
codeLens = 11,
colorDecorators = 12,
columnSelection = 13,
comments = 14,
contextmenu = 15,
copyWithSyntaxHighlighting = 16,
cursorBlinking = 17,
cursorSmoothCaretAnimation = 18,
cursorStyle = 19,
cursorSurroundingLines = 20,
cursorSurroundingLinesStyle = 21,
cursorWidth = 22,
disableLayerHinting = 23,
disableMonospaceOptimizations = 24,
dragAndDrop = 25,
emptySelectionClipboard = 26,
extraEditorClassName = 27,
fastScrollSensitivity = 28,
find = 29,
fixedOverflowWidgets = 30,
folding = 31,
foldingStrategy = 32,
foldingHighlight = 33,
unfoldOnClickAfterEndOfLine = 34,
fontFamily = 35,
fontInfo = 36,
fontLigatures = 37,
fontSize = 38,
fontWeight = 39,
formatOnPaste = 40,
formatOnType = 41,
glyphMargin = 42,
gotoLocation = 43,
hideCursorInOverviewRuler = 44,
highlightActiveIndentGuide = 45,
hover = 46,
inDiffEditor = 47,
letterSpacing = 48,
lightbulb = 49,
lineDecorationsWidth = 50,
lineHeight = 51,
lineNumbers = 52,
lineNumbersMinChars = 53,
links = 54,
matchBrackets = 55,
minimap = 56,
mouseStyle = 57,
mouseWheelScrollSensitivity = 58,
mouseWheelZoom = 59,
multiCursorMergeOverlapping = 60,
multiCursorModifier = 61,
multiCursorPaste = 62,
occurrencesHighlight = 63,
overviewRulerBorder = 64,
overviewRulerLanes = 65,
padding = 66,
parameterHints = 67,
peekWidgetDefaultFocus = 68,
definitionLinkOpensInPeek = 69,
quickSuggestions = 70,
quickSuggestionsDelay = 71,
readOnly = 72,
renderControlCharacters = 73,
renderIndentGuides = 74,
renderFinalNewline = 75,
renderLineHighlight = 76,
renderValidationDecorations = 77,
renderWhitespace = 78,
revealHorizontalRightPadding = 79,
roundedSelection = 80,
rulers = 81,
scrollbar = 82,
scrollBeyondLastColumn = 83,
scrollBeyondLastLine = 84,
scrollPredominantAxis = 85,
selectionClipboard = 86,
selectionHighlight = 87,
selectOnLineNumbers = 88,
showFoldingControls = 89,
showUnused = 90,
snippetSuggestions = 91,
smoothScrolling = 92,
stopRenderingLineAfter = 93,
suggest = 94,
suggestFontSize = 95,
suggestLineHeight = 96,
suggestOnTriggerCharacters = 97,
suggestSelection = 98,
tabCompletion = 99,
useTabStops = 100,
wordSeparators = 101,
wordWrap = 102,
wordWrapBreakAfterCharacters = 103,
wordWrapBreakBeforeCharacters = 104,
wordWrapColumn = 105,
wordWrapMinified = 106,
wrappingIndent = 107,
wrappingStrategy = 108,
editorClassName = 109,
pixelRatio = 110,
tabFocusMode = 111,
layoutInfo = 112,
wrappingInfo = 113
renameOnType = 10,
autoSurround = 11,
codeLens = 12,
colorDecorators = 13,
columnSelection = 14,
comments = 15,
contextmenu = 16,
copyWithSyntaxHighlighting = 17,
cursorBlinking = 18,
cursorSmoothCaretAnimation = 19,
cursorStyle = 20,
cursorSurroundingLines = 21,
cursorSurroundingLinesStyle = 22,
cursorWidth = 23,
disableLayerHinting = 24,
disableMonospaceOptimizations = 25,
dragAndDrop = 26,
emptySelectionClipboard = 27,
extraEditorClassName = 28,
fastScrollSensitivity = 29,
find = 30,
fixedOverflowWidgets = 31,
folding = 32,
foldingStrategy = 33,
foldingHighlight = 34,
unfoldOnClickAfterEndOfLine = 35,
fontFamily = 36,
fontInfo = 37,
fontLigatures = 38,
fontSize = 39,
fontWeight = 40,
formatOnPaste = 41,
formatOnType = 42,
glyphMargin = 43,
gotoLocation = 44,
hideCursorInOverviewRuler = 45,
highlightActiveIndentGuide = 46,
hover = 47,
inDiffEditor = 48,
letterSpacing = 49,
lightbulb = 50,
lineDecorationsWidth = 51,
lineHeight = 52,
lineNumbers = 53,
lineNumbersMinChars = 54,
links = 55,
matchBrackets = 56,
minimap = 57,
mouseStyle = 58,
mouseWheelScrollSensitivity = 59,
mouseWheelZoom = 60,
multiCursorMergeOverlapping = 61,
multiCursorModifier = 62,
multiCursorPaste = 63,
occurrencesHighlight = 64,
overviewRulerBorder = 65,
overviewRulerLanes = 66,
padding = 67,
parameterHints = 68,
peekWidgetDefaultFocus = 69,
definitionLinkOpensInPeek = 70,
quickSuggestions = 71,
quickSuggestionsDelay = 72,
readOnly = 73,
renderControlCharacters = 74,
renderIndentGuides = 75,
renderFinalNewline = 76,
renderLineHighlight = 77,
renderValidationDecorations = 78,
renderWhitespace = 79,
revealHorizontalRightPadding = 80,
roundedSelection = 81,
rulers = 82,
scrollbar = 83,
scrollBeyondLastColumn = 84,
scrollBeyondLastLine = 85,
scrollPredominantAxis = 86,
selectionClipboard = 87,
selectionHighlight = 88,
selectOnLineNumbers = 89,
showFoldingControls = 90,
showUnused = 91,
snippetSuggestions = 92,
smoothScrolling = 93,
stopRenderingLineAfter = 94,
suggest = 95,
suggestFontSize = 96,
suggestLineHeight = 97,
suggestOnTriggerCharacters = 98,
suggestSelection = 99,
tabCompletion = 100,
useTabStops = 101,
wordSeparators = 102,
wordWrap = 103,
wordWrapBreakAfterCharacters = 104,
wordWrapBreakBeforeCharacters = 105,
wordWrapColumn = 106,
wordWrapMinified = 107,
wrappingIndent = 108,
wrappingStrategy = 109,
editorClassName = 110,
pixelRatio = 111,
tabFocusMode = 112,
layoutInfo = 113,
wrappingInfo = 114
}

/**
Expand Down
11 changes: 11 additions & 0 deletions src/vs/editor/contrib/rename/media/onTypeRename.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

.monaco-editor .on-type-rename-decoration {
background: rgba(255, 0, 0, 0.3);
border-left: 1px solid rgba(255, 0, 0, 0.3);
/* So border can be transparent */
background-clip: padding-box;
}
Loading