Skip to content

Commit

Permalink
Refactor focusing to contextLine (apache#24613)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexeyinkin committed Dec 15, 2022
1 parent aa6cc16 commit 829806c
Show file tree
Hide file tree
Showing 7 changed files with 432 additions and 228 deletions.
267 changes: 267 additions & 0 deletions playground/frontend/_build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,267 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* License); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an AS IS BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/


apply plugin: 'org.apache.beam.module'
apply plugin: 'base'
applyDockerNature()

def playgroundBackendUrl = project.playgroundBackendUrl
def analyticsUA = project.analyticsUA
def playgroundBackendJavaRouteUrl = project.playgroundBackendJavaRouteUrl
def playgroundBackendGoRouteUrl = project.playgroundBackendGoRouteUrl
def playgroundBackendPythonRouteUrl = project.playgroundBackendPythonRouteUrl
def playgroundBackendScioRouteUrl = project.playgroundBackendScioRouteUrl

def playgroundJobServerProject = "${project.path.replace('-container', '')}"

description = project(playgroundJobServerProject).description + " :: Container"

configurations {
dockerDependency
// print(dockerDependency)
}

dependencies {
dockerDependency project(path: playgroundJobServerProject, configuration: "shadow")
// print(dockerDependency)
}

task generate {
dependsOn("playground_components:generate")

dependsOn("generateCode")

group = "build"
description = "Generates all generated files."
}

task printPath {
doLast {
exec {
executable("printenv")
args("PATH")
}
}
}

task analyze {
dependsOn("playground_components:generateCode")
dependsOn("generateCode")

group = "verification"
description = "Analyze dart code"

doLast {
exec {
// Exact paths instead of '.' so it does not go into playground_components
executable("dart")
args("analyze", "lib", "test")
}
}
}

task pubGet {
group = "build"
description = "Get packages for the playground frontend project"
doLast {
exec {
executable("flutter")
args("pub", "get")
}
}
}

task format {
group = "build"
description = "Idiomatically format Dart source code"
doLast {
exec {
// Exact paths instead of '.' so it does not go into playground_components
executable("dart")
args("format", "lib", "test")
}
}
}

task run {
group = "application"
description = "Run application on Google Chrome"
doLast {
exec {
executable("flutter")
args("run", "-d", "chrome")
}
}
}

task test {
dependsOn("playground_components:generateCode")
dependsOn("generateCode")

group = "verification"
description = "flutter test"

doLast {
exec {
executable("flutter")
args("test")
}
}
}

task precommit {
dependsOn("playground_components:precommit")

dependsOn("analyze")
dependsOn("test")
}

task generateCode {
dependsOn("playground_components:generateCode")

dependsOn("cleanFlutter")
dependsOn("pubGet")

group = "build"
description = "Generate code"

doLast {
exec {
executable("flutter")
args("pub", "run", "build_runner", "build", "--delete-conflicting-outputs")
}
}
}

task cleanFlutter {
group = "build"
description = "Remove build artifacts"

doLast {
exec {
executable("flutter")
args("clean")
}
}
}

task cleanGenerated {
dependsOn("playground_components:cleanGenerated")

group = "build"
description = "Remove build artifacts"

doLast {
println("Deleting:")

deleteFilesByRegExp(".*\\.g\\.dart\$")
deleteFilesByRegExp(".*\\.gen\\.dart\$")
deleteFilesByRegExp(".*\\.mocks\\.dart\$")
}
}

ext.deleteFilesByRegExp = { re ->
// Prints file names.
exec {
executable("find")
args("assets", "lib", "test", "-regex", re)
}

// Actually deletes them.
exec {
executable("find")
args("assets", "lib", "test", "-regex", re, "-delete")
}
}

task copyDockerfileDependencies(type: Copy) {
group = "build"
description = "Copy files that required to build docker container"
copy {
from '.'
into 'build/'
exclude 'build'
exclude 'Dockerfile'
}
copy {
from '../playground'
into 'build/playground'
}
}

docker {
group = "build"
description = "Build container for playground frontend application"
name containerImageName(
name: project.docker_image_default_repo_prefix + "playground-frontend",
root: project.rootProject.hasProperty(["docker-repository-root"]) ?
project.rootProject["docker-repository-root"] :
project.docker_image_default_repo_root)
files "./build/"
tags containerImageTags()
buildArgs(['FLUTTER_VERSION': project.rootProject.hasProperty(["flutter-version"]) ?
project.rootProject["flutter-version"] :
"3.3.2" ])
}

println(docker)
println(containerImageName)

// Ensure that we build the required resources and copy and file dependencies from related projects
dockerPrepare.dependsOn copyDockerfileDependencies

task("createConfig") {
group = "build"
description = "Generate config for the playground frontend project"
doLast {
def configFileName = "config.g.dart"
def modulePath = project(":playground:frontend").projectDir.absolutePath
def file = new File(modulePath + "/lib", configFileName)
file.write("""/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
const String kApiClientURL =
'${playgroundBackendUrl}';
const String kAnalyticsUA = '${analyticsUA}';
const String kApiJavaClientURL =
'${playgroundBackendJavaRouteUrl}';
const String kApiGoClientURL =
'${playgroundBackendGoRouteUrl}';
const String kApiPythonClientURL =
'${playgroundBackendPythonRouteUrl}';
const String kApiScioClientURL =
'${playgroundBackendScioRouteUrl}';
""")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,9 @@ class EmbeddedEditor extends StatelessWidget {
return const LoadingIndicator();
}

return SnippetEditor(
return EditorTextArea(
controller: snippetController,
isEditable: isEditable,
goToContextLine: false,
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,9 @@ class CodeTextAreaWrapper extends StatelessWidget {
child: Stack(
children: [
Positioned.fill(
child: SnippetEditor(
child: EditorTextArea(
controller: snippetController,
isEditable: true,
goToContextLine: true,
),
),
Positioned(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
* limitations under the License.
*/

import 'dart:math';

import 'package:flutter/widgets.dart';
import 'package:flutter_code_editor/flutter_code_editor.dart';
import 'package:get_it/get_it.dart';
Expand Down Expand Up @@ -77,6 +79,7 @@ class SnippetEditingController extends ChangeNotifier {
codeController.removeListener(_onCodeControllerChanged);
setSource(example.source);
_applyViewOptions(viewOptions);
_toStartOfContextLineIfAny();
codeController.addListener(_onCodeControllerChanged);

notifyListeners();
Expand All @@ -100,6 +103,27 @@ class SnippetEditingController extends ChangeNotifier {
}
}

void _toStartOfContextLineIfAny() {
final contextLine = selectedExample?.contextLine;

if (contextLine == null) {
return;
}

_toStartOfFullLine(max(contextLine - 1, 0));
}

void _toStartOfFullLine(int line) {
final fullPosition = codeController.code.lines.lines[line].textRange.start;
final visiblePosition = codeController.code.hiddenRanges.cutPosition(
fullPosition,
);

codeController.selection = TextSelection.collapsed(
offset: visiblePosition,
);
}

Example? get selectedExample => _selectedExample;

ExampleLoadingDescriptor? get descriptor => _descriptor;
Expand Down
Loading

0 comments on commit 829806c

Please sign in to comment.