+
Skip to content

Performance improvements #119

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

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all 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
22 changes: 0 additions & 22 deletions client/extension/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,6 @@ export async function activate(context: ExtensionContext) {
let promptVanillaPath = new NotificationType<string, void>('promptVanillaPath')
interface DidFocusFile { uri : string }
let didFocusFile = new NotificationType<DidFocusFile, void>('didFocusFile')
let request = new RequestType<Position, string, void, void>('getWordRangeAtPosition');
let status: Disposable;
interface UpdateFileList { fileList: FileListItem[] }
let updateFileList = new NotificationType<UpdateFileList, void>('updateFileList');
Expand Down Expand Up @@ -250,27 +249,6 @@ export async function activate(context: ExtensionContext) {
);

})
client.onRequest(request, (param: any, _) => {
console.log("recieved request " + request.method + " " + param)
let uri = Uri.parse(param.uri);
let document = window.visibleTextEditors.find((v) => v.document.uri.path == uri.path).document
//let document = window.activeTextEditor.document;
let position = new Position(param.position.line, param.position.character)
let wordRange = document.getWordRangeAtPosition(position, /"?([^\s]+)"?/g);
if (wordRange === undefined) {
return "none";
}
else {
let text = document.getText(wordRange);
console.log("wordAtPos " + text);
if (text.trim().length == 0) {
return "none";
}
else {
return text;
}
}
});
client.onNotification(updateFileList, (params: UpdateFileList) =>
{
fileList = params.fileList;
Expand Down
15 changes: 15 additions & 0 deletions fsharp-language-server.sln
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{520503FB
EndProject
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "build", "build\build.fsproj", "{38151F7F-F903-4EEC-A6D8-325FC534FBDC}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CSharpExtensions", "src\CSharpExtensions\CSharpExtensions.csproj", "{61AAD9EA-772E-4F7A-A23F-B4F24F35D4C5}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -103,9 +105,22 @@ Global
{38151F7F-F903-4EEC-A6D8-325FC534FBDC}.Release|x64.Build.0 = Release|Any CPU
{38151F7F-F903-4EEC-A6D8-325FC534FBDC}.Release|x86.ActiveCfg = Release|Any CPU
{38151F7F-F903-4EEC-A6D8-325FC534FBDC}.Release|x86.Build.0 = Release|Any CPU
{61AAD9EA-772E-4F7A-A23F-B4F24F35D4C5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{61AAD9EA-772E-4F7A-A23F-B4F24F35D4C5}.Debug|Any CPU.Build.0 = Debug|Any CPU
{61AAD9EA-772E-4F7A-A23F-B4F24F35D4C5}.Debug|x64.ActiveCfg = Debug|Any CPU
{61AAD9EA-772E-4F7A-A23F-B4F24F35D4C5}.Debug|x64.Build.0 = Debug|Any CPU
{61AAD9EA-772E-4F7A-A23F-B4F24F35D4C5}.Debug|x86.ActiveCfg = Debug|Any CPU
{61AAD9EA-772E-4F7A-A23F-B4F24F35D4C5}.Debug|x86.Build.0 = Debug|Any CPU
{61AAD9EA-772E-4F7A-A23F-B4F24F35D4C5}.Release|Any CPU.ActiveCfg = Release|Any CPU
{61AAD9EA-772E-4F7A-A23F-B4F24F35D4C5}.Release|Any CPU.Build.0 = Release|Any CPU
{61AAD9EA-772E-4F7A-A23F-B4F24F35D4C5}.Release|x64.ActiveCfg = Release|Any CPU
{61AAD9EA-772E-4F7A-A23F-B4F24F35D4C5}.Release|x64.Build.0 = Release|Any CPU
{61AAD9EA-772E-4F7A-A23F-B4F24F35D4C5}.Release|x86.ActiveCfg = Release|Any CPU
{61AAD9EA-772E-4F7A-A23F-B4F24F35D4C5}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{D0C97655-008A-4376-87A3-FD072D076F16} = {29A9E10D-C8C7-416D-B32D-820658A129A6}
{AD9284CA-9934-4A4B-9C5C-AE680DFE0451} = {29A9E10D-C8C7-416D-B32D-820658A129A6}
{61AAD9EA-772E-4F7A-A23F-B4F24F35D4C5} = {29A9E10D-C8C7-416D-B32D-820658A129A6}
EndGlobalSection
EndGlobal
1 change: 1 addition & 0 deletions fsharp-language-server.sln.DotSettings.user
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:String x:Key="/Default/Environment/AssemblyExplorer/XmlDocument/@EntryValue">&lt;AssemblyExplorer&gt;&#xD;
&lt;Assembly Path="C:\Users\Thomas\Git\cwtools-vscode\paket-files\git\localfilesystem\cwtools\CWTools\bin\Debug\netstandard2.0\CWTools.dll" /&gt;&#xD;
&lt;Assembly Path="D:\Code\Project\GitProject\cwtools\CWTools\bin\Release\net9.0\CWTools.dll" /&gt;&#xD;
&lt;/AssemblyExplorer&gt;</s:String></wpf:ResourceDictionary>
2 changes: 1 addition & 1 deletion paket.lock
Original file line number Diff line number Diff line change
Expand Up @@ -701,4 +701,4 @@ GROUP git

GIT
remote: https://www.github.com/cwtools/cwtools
(50e9a6608be9dde31089be84174b092d1f0c44b4)
(822ff82976318a3f4b46b582921c96d5f6578b6f)
10 changes: 10 additions & 0 deletions src/CSharpExtensions/CSharpExtensions.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<WarningsAsErrors>nullable</WarningsAsErrors>
</PropertyGroup>

</Project>
49 changes: 49 additions & 0 deletions src/CSharpExtensions/DocumentStoreHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
namespace CSharpExtensions;

public static class DocumentStoreHelper
{
public static string GetTextAtPosition(string fileText, int line, int character)
{
int currentLine = 0;
ReadOnlySpan<char> currentLineText = null;
foreach (var lineText in fileText.AsSpan().EnumerateLines())
{
if (currentLine == line)
{
currentLineText = lineText;
break;
}
++currentLine;
}

if (currentLineText.IsEmpty)
{
return string.Empty;
}

int start = 0;
int end = 0;
ReadOnlySpan<char> excludedChars = ['=', ' ', '{', '}', '\t', '"'];
int adjustedPosition = Math.Min(character, currentLineText.Length - 1);
for (int offset = adjustedPosition; offset >= 0; offset--)
{
if (excludedChars.Contains(currentLineText[offset]))
{
break;
}
start = offset;
}

for (int offset = adjustedPosition; offset < currentLineText.Length; offset++)
{
if (excludedChars.Contains(currentLineText[offset]))
{
break;
}
end = offset;
}

int length = start == 0 && end == 0 ? 0 : end - start + 1;
return currentLineText.Slice(start, length).ToString();
}
}
15 changes: 11 additions & 4 deletions src/LSP/DocumentStore.fs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
namespace LSP

open LSP.Log
open System
open CSharpExtensions
open LSP.Log
open System.IO
open System.Collections.Generic
open System.Text
Expand All @@ -13,7 +14,7 @@ type private Version = {
}

module DocumentStoreUtils =
let findRange(text: StringBuilder, range: Range): int * int =
let findRange(text: StringBuilder, range: Range): struct (int * int) =
let mutable line = 0
let mutable char = 0
let mutable startOffset = 0
Expand Down Expand Up @@ -41,7 +42,7 @@ type DocumentStore() =
let patch(doc: VersionedTextDocumentIdentifier, range: Range, text: string): unit =
let file = FileInfo(doc.uri.LocalPath)
let existing = activeDocuments.[file.FullName]
let startOffset, endOffset = findRange(existing.text, range)
let struct (startOffset, endOffset) = findRange(existing.text, range)
existing.text.Remove(startOffset, endOffset - startOffset) |> ignore
existing.text.Insert(startOffset, text) |> ignore
existing.version <- doc.version
Expand Down Expand Up @@ -89,4 +90,10 @@ type DocumentStore() =
activeDocuments.Remove(file.FullName) |> ignore

member this.OpenFiles(): FileInfo list =
[for file in activeDocuments.Keys do yield FileInfo(file)]
[for file in activeDocuments.Keys do yield FileInfo(file)]

member this.GetTextAtPosition(fileUri: Uri, position: Position): string =
match this.GetText(FileInfo(fileUri.LocalPath)) with
| Some(text) ->
DocumentStoreHelper.GetTextAtPosition(text, position.line, position.character)
| None -> String.Empty
5 changes: 4 additions & 1 deletion src/LSP/LSP.fsproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<TargetFramework>net9.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<Compile Include="Log.fs" />
Expand All @@ -12,5 +12,8 @@
<Compile Include="DocumentStore.fs" />
<Compile Include="LanguageServer.fs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\CSharpExtensions\CSharpExtensions.csproj" />
</ItemGroup>
<Import Project="..\..\.paket\Paket.Restore.targets" />
</Project>
15 changes: 5 additions & 10 deletions src/Main/LanguageServerFeatures.fs
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,9 @@ module LanguageServerFeatures =
}
}

let getWordAtPos (client : ILanguageClient) pos doc =
let json = serializerFactory<GetWordRangeAtPositionParams> defaultJsonWriteOptions ({ position = pos; uri = doc })
client.CustomRequest("getWordRangeAtPosition", json)

let getPathFromDoc (doc : Uri) =
let u = doc
if System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(OSPlatform.Windows) && u.LocalPath.StartsWith "/"
if RuntimeInformation.IsOSPlatform(OSPlatform.Windows) && u.LocalPath.StartsWith "/"
then u.LocalPath.Substring(1)
else u.LocalPath

Expand Down Expand Up @@ -64,17 +60,16 @@ module LanguageServerFeatures =

let hoverDocument (eu4GameObj) (hoi4GameObj) (stlGameObj) (ck2GameObj) (irGameObj) (vic2GameObj) (ck3GameObj) (vic3GameObj: 'h option) (customGameObj) (client : ILanguageClient) (docs : DocumentStore) (doc : Uri) (pos: LSP.Types.Position) =
async {
let! word = getWordAtPos client pos doc
let unescapedword = word.ToString().Replace("\\\"", "\"").Trim('"')
let unescapedWord = docs.GetTextAtPosition(doc, pos)
let position = Pos.fromZ pos.line pos.character
let path = getPathFromDoc doc
let hoverFunction (game : IGame<_>) =
let symbolInfo = game.InfoAtPos position path (docs.GetText (FileInfo (doc.LocalPath)) |> Option.defaultValue "")
let scopeContext = game.ScopesAtPos position (path) (docs.GetText (FileInfo (doc.LocalPath)) |> Option.defaultValue "")
let allEffects = game.ScriptedEffects() @ game.ScriptedTriggers()
eprintfn "Looking for effect %s in the %i effects loaded" (word.ToString()) (allEffects.Length)
let hovered = allEffects |> List.tryFind (fun e -> e.Name.GetString() = unescapedword)
let lochover = lochoverFromInfo (game.References().Localisation) symbolInfo unescapedword
eprintfn "Looking for effect %s in the %i effects loaded" (unescapedWord.ToString()) (allEffects.Length)
let hovered = allEffects |> List.tryFind (fun e -> e.Name.GetString() = unescapedWord)
let lochover = lochoverFromInfo (game.References().Localisation) symbolInfo unescapedWord
let scopesExtra =
if scopeContext.IsNone then "" else
let scopes = scopeContext.Value
Expand Down
Loading
Loading
点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载