Skip to content

Commit

Permalink
added ExtractType and ExtractInterface refactoring via rename lib (#133)
Browse files Browse the repository at this point in the history
* added Extract Type refactoring option
* added Extract Interface refactoring option, fixes vshaxe/vshaxe#649
* added auto-discovery of classpath for rename cache - deprecating haxe.renameSourceFolders setting for Haxe 4
* added formatting option to text edits
* added Extract Method refactoring option, fixes vshaxe/vshaxe#632
* added Extract Constructor Params refactor module
* added Rewrite Vars to Finals and vice versa
* added disableRefactorCache to allow disabling refactor cache
* added Wrap With Try…Catch refactor module
* added a delay for recently renamed files to ensure refactor cache doesn't see partial changes / duplicate types
* added null check for hover.range, fixes vshaxe/vshaxe#641
* updated formatter and json2object libs
* refactored rename cache
* fixed repeated rename operations breaking rename cache
* fixed rename / refactor operations not working on unsaved files
* fixed formatter check failing with formatter git version
* remove full cache invalidation before rename / refactor operation
  • Loading branch information
AlexHaxe authored Dec 23, 2024
1 parent 900c057 commit 2f03d9d
Show file tree
Hide file tree
Showing 23 changed files with 967 additions and 822 deletions.
1 change: 1 addition & 0 deletions .github/workflows/formatting.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ jobs:
submodules: true
- run: |
npm ci
npx lix install haxelib:formatter
npx lix run formatter -s . --check
4 changes: 2 additions & 2 deletions .haxerc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"version": "b537e99",
"version": "2dc801f",
"resolveLibs": "scoped"
}
}
8 changes: 4 additions & 4 deletions haxe_libraries/formatter.hxml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# @install: lix --silent download "haxelib:/formatter#1.17.1" into formatter/1.17.1/haxelib
# @run: haxelib run-dir formatter "${HAXE_LIBCACHE}/formatter/1.17.1/haxelib"
-cp ${HAXE_LIBCACHE}/formatter/1.17.1/haxelib/src
-D formatter=1.17.1
# @install: lix --silent download "haxelib:/formatter#1.18.0" into formatter/1.18.0/haxelib
# @run: haxelib run-dir formatter "${HAXE_LIBCACHE}/formatter/1.18.0/haxelib"
-cp ${HAXE_LIBCACHE}/formatter/1.18.0/haxelib/src
-D formatter=1.18.0
4 changes: 2 additions & 2 deletions haxe_libraries/json2object.hxml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# @install: lix --silent download "gh://github.com/elnabo/json2object#429986134031cbb1980f09d0d3d642b4b4cbcd6a" into json2object/3.11.0/github/429986134031cbb1980f09d0d3d642b4b4cbcd6a
# @install: lix --silent download "gh://github.com/elnabo/json2object#a75859de1e966c09e73591b6c9186086c143fe60" into json2object/3.11.0/github/a75859de1e966c09e73591b6c9186086c143fe60
-lib hxjsonast
-cp ${HAXE_LIBCACHE}/json2object/3.11.0/github/429986134031cbb1980f09d0d3d642b4b4cbcd6a/src
-cp ${HAXE_LIBCACHE}/json2object/3.11.0/github/a75859de1e966c09e73591b6c9186086c143fe60/src
-D json2object=3.11.0
6 changes: 3 additions & 3 deletions haxe_libraries/rename.hxml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# @install: lix --silent download "haxelib:/rename#2.3.0" into rename/2.3.0/haxelib
-cp ${HAXE_LIBCACHE}/rename/2.3.0/haxelib/src
-D rename=2.3.0
# @install: lix --silent download "haxelib:/rename#3.0.0" into rename/3.0.0/haxelib
-cp ${HAXE_LIBCACHE}/rename/3.0.0/haxelib/src
-D rename=3.0.0
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@vshaxe/haxe-language-server",
"version": "2.32.2",
"version": "2.33.0",
"devDependencies": {
"lix": "^15.12.0",
"terser": "^5.15.0"
Expand Down
2 changes: 2 additions & 0 deletions src/haxeLanguageServer/Configuration.hx
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ typedef UserConfig = {
var importsSortOrder:ImportsSortOrderConfig;
var maxCompletionItems:Int;
var renameSourceFolders:Array<String>;
var disableRefactorCache:Bool;
var inlayHints:InlayHintConfig;
var serverRecording:ServerRecordingConfig;
}
Expand Down Expand Up @@ -202,6 +203,7 @@ class Configuration {
importsSortOrder: AllAlphabetical,
maxCompletionItems: 1000,
renameSourceFolders: ["src", "source", "Source", "test", "tests"],
disableRefactorCache: false,
inlayHints: {
variableTypes: false,
parameterNames: false,
Expand Down
15 changes: 14 additions & 1 deletion src/haxeLanguageServer/Context.hx
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,14 @@ import haxeLanguageServer.features.haxe.GotoDefinitionFeature;
import haxeLanguageServer.features.haxe.GotoImplementationFeature;
import haxeLanguageServer.features.haxe.GotoTypeDefinitionFeature;
import haxeLanguageServer.features.haxe.InlayHintFeature;
import haxeLanguageServer.features.haxe.RefactorFeature;
import haxeLanguageServer.features.haxe.RenameFeature;
import haxeLanguageServer.features.haxe.SignatureHelpFeature;
import haxeLanguageServer.features.haxe.WorkspaceSymbolsFeature;
import haxeLanguageServer.features.haxe.codeAction.CodeActionFeature;
import haxeLanguageServer.features.haxe.documentSymbols.DocumentSymbolsFeature;
import haxeLanguageServer.features.haxe.foldingRange.FoldingRangeFeature;
import haxeLanguageServer.features.haxe.refactoring.RefactorCache;
import haxeLanguageServer.server.DisplayResult;
import haxeLanguageServer.server.HaxeServer;
import haxeLanguageServer.server.ServerRecording;
Expand Down Expand Up @@ -64,6 +66,7 @@ class Context {
@:nullSafety(Off) public var findReferences(default, null):FindReferencesFeature;
@:nullSafety(Off) public var determinePackage(default, null):DeterminePackageFeature;
@:nullSafety(Off) public var diagnostics(default, null):DiagnosticsFeature;
@:nullSafety(Off) public var refactorCache(default, null):RefactorCache;
public var experimental(default, null):Null<ExperimentalCapabilities>;

var activeEditor:Null<DocumentUri>;
Expand Down Expand Up @@ -376,7 +379,8 @@ class Context {
new GotoTypeDefinitionFeature(this);
findReferences = new FindReferencesFeature(this);
determinePackage = new DeterminePackageFeature(this);
new RenameFeature(this);
refactorCache = new RefactorCache(this);
new RenameFeature(this, refactorCache);
diagnostics = new DiagnosticsFeature(this);
new CodeActionFeature(this);
new CodeLensFeature(this);
Expand All @@ -390,6 +394,7 @@ class Context {
} else {
haxeServer.restart(reason, function() {
onServerStarted();
refactorCache.initClassPaths();
if (activeEditor != null) {
publishDiagnostics(activeEditor);
}
Expand All @@ -416,6 +421,7 @@ class Context {
serverRecording.onDidChangeTextDocument(event);
invalidateFile(uri);
documents.onDidChangeTextDocument(event);
refactorCache.invalidateFile(uri.toFsPath().toString());
}
}

Expand All @@ -432,6 +438,7 @@ class Context {
if (isUriSupported(uri)) {
publishDiagnostics(uri);
invalidated.remove(uri.toString());
refactorCache.invalidateFile(uri.toFsPath().toString());
}
}

Expand All @@ -447,6 +454,9 @@ class Context {
invalidateFile(change.uri);
case _:
}
if (change.uri.isHaxeFile()) {
refactorCache.invalidateFile(change.uri.toFsPath().toString());
}
}
}

Expand All @@ -466,6 +476,9 @@ class Context {
}

function onDidChangeActiveTextEditor(params:{uri:DocumentUri}) {
if (!params.uri.isFile() || !params.uri.isHaxeFile()) {
return;
}
activeEditor = params.uri;
final document = documents.getHaxe(params.uri);
if (document == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ class DeterminePackageFeature {

function handleJsonRpc(path:FsPath, token:Null<CancellationToken>, resolve:{pack:String}->Void, reject:ResponseError<NoData>->Void) {
context.callHaxeMethod(DisplayMethods.DeterminePackage, {file: path}, token, function(result) {
if (result == null) {
reject(ResponseError.internalError("unable to determine package of module"));
return null;
}
resolve({pack: result.join(".")});
return null;
}, reject.handler());
Expand Down
2 changes: 1 addition & 1 deletion src/haxeLanguageServer/features/haxe/HoverFeature.hx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class HoverFeature {
function handleJsonRpc(params:TextDocumentPositionParams, token:CancellationToken, resolve:Null<Hover>->Void, reject:ResponseError<NoData>->Void,
doc:HxTextDocument, offset:Int) {
context.callHaxeMethod(DisplayMethods.Hover, {file: doc.uri.toFsPath(), contents: doc.content, offset: offset}, token, function(hover) {
if (hover == null) {
if (hover == null || hover.range == null) {
resolve(null);
} else {
final range = context.displayOffsetConverter.byteRangeToCharacterRange(hover.range, doc);
Expand Down
2 changes: 1 addition & 1 deletion src/haxeLanguageServer/features/haxe/InlayHintFeature.hx
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class InlayHintFeature {
if (root == null) {
return reject.noFittingDocument(uri);
}
#if debug
#if debug_inlayhints
trace('[inlayHints] requesting inlay hints for $fileName lines ${params.range.start.line}-${params.range.end.line}');
#end
removeCancelledRequests();
Expand Down
Loading

0 comments on commit 2f03d9d

Please sign in to comment.