LSP: Cannot get document symbol - language-server-protocol

I'm learning LSP and am right now trying to get document symbols. I use Felix Becker PHP language server. No matter what I try I cannot get back the symbols.
I have tried to log what the Language Server receives and here it is (tried to omit sensitive data):
{"id":1,"method":"initialize","params":{"initializationOptions":{},"rootUri":"file:\/\/\/Users\/stef\/Projects\/TestApp","capabilities":{},"rootPath":"\/Users\/stef\/Projects\/TestApp","trace":"verbose","processId":null,"workspaceFolders":[{"uri":"file:\/\/\/Users\/stef\/Projects\/TestApp","name":"TestApp"}]},"jsonrpc":"2.0"}
{"id":2,"method":"initialized","params":{},"jsonrpc":"2.0"}
{"id":3,"method":"textDocument\/didOpen","params":{"textDocument":{"uri":"file:\/\/\/Users\/stef\/Projects\/TestApp\/models\/User.php","languageId":"php","version":1,"text":"<?php\\n\\nnamespace app\\models;\\n\\nuse Yii;\\n\\n\/**\\n * This is the model class for table \"Users\".\\n *\\n * #property integer $id\\n * #property string $User\\n * #property integer $route\\n * #property string $bus\\n * #property string $start\\n * #property string $end\\n * #property string $dept_date\\n * #property string $dept_time\\n * #property integer $customer\\n * #property integer $issued_on\\n * #property string $machine_serial\\n * #property integer $price\\n * #property integer $is_deleted\\n * #property string $OOOPS\\n * #property integer $expired_in\\n * #property integer $created_at\\n * #property integer $created_by\\n * #property integer $updated_at\\n * #property integer $updated_by\\n *\\n * #property PlannedRoutes $deptDate\\n * #property Buses $bus0\\n * #property Customers $customer0\\n * #property Stops $end0\\n * #property POSes $machineSerial\\n * #property Routes $route0\\n * #property Stops $start0\\n *\/\\nclass User extends TenantModel\\n{\\n use \\app\\traits\\Signature;\\n\\n const OOOPS_KOOK = 'BO';\\n const OOOPS_TEMPORARY_KOOK = 'BT';\\n const OOOPS_CANCELLED = 'CA';\\n const OOOPS_CONFIRMED = 'CO';\\n const OOOPS_FOOF_User = 'CT';\\n const OOOPS_FREE = 'FR';\\n \\n public $RWF;\\n public $UGS;\\n public $FIB;\\n public $USD;\\n public $seats; \/\/ total bus seats\\n public $Users; \/\/ sold Users\\n public $bookings; \/\/ valid bookings\\n public $promotion; \/\/ Promotion Users\\n public $staff; \/\/ Staff Users\\n public $location; \/\/ Staff Location\\n public $day; \/\/ User day like Monday\\n public $author; \/\/ Staff who created User\\n public $broute; \/\/ Main Route\\n \\n public $FOOFs; \/\/total FOOFs sold\\n public $crevenue; \/\/total FOOFs Revenue\\n \/**\\n * #inheritdoc\\n *\/\\n ....some sensitive data omitted...}}},"jsonrpc":"2.0"}
{"id":4,"method":"textDocument\/documentSymbol","params":{"textDocument":{"uri":"file:\/\/\/Users\/stef\/Projects\/TestApp\/models\/User.php"}},"jsonrpc":"2.0"}
and here is a logged response from the server
A lot of {"method":"window\/logMessage","params"....
A lot of {"method":"textDocument\/publishDiagnostics"...
Finally I get
{"result":null,"id":3,"jsonrpc":"2.0"}Content-Type: application/vscode-jsonrpc; charset=utf8
Content-Length: 36
I cannot find why the server is not responding with the symbols. I tried VS Plugin by the same author and It is working fine which means it I mess up somewhere. But can't just figure it out!
Any help is appreciated.

It happened that my JSON RPC payload contained unescaped 0x09 or tab control character. Replacing it with\t solved the problem

Related

django-import-export - Export one to many relationship with ForeignKeyWidget - returns an empty Field

I am trying to use the dajngo-import-export package to export data from two tables with a one to many relationship. I have a custom ForeignKeyWidget class that overrides the get_queryset method.
The problem is that the export returns an empty field - no errors, just an empty field. I also tried just using the ForeignKeyWidget without the custom class/get_queryset - but I get the same result.
Does anyone see what I'm doing wrong here?
#admin.py
from import_export import resources
from import_export.fields import Field
from import_export.widgets import ForeignKeyWidget
class SlateDocResource(resources.ModelResource):
actbreaks = Field(
column_name="actbreaks",
attribute="id",
widget=ActBreaksForeignKeyWidget(ActTimecodes, "slatedoc_id"),
)
class Meta:
model = SlateDoc
fields = [
"actbreaks",
]
class ActBreaksForeignKeyWidget(ForeignKeyWidget):
def get_queryset(self, value, row, *args, **kwargs):
qs = ActTimecodes.objects.filter(slatedoc_id=self.pk)
print(qs.values())
return qs
#models.py
class SlateDoc(models.Model):
#primary Model - fields not listed here.
class ActTimecodes(models.Model):
#Secondary model - every slatedoc can have multiple instances of ActTimecodes
slatedoc = models.ForeignKey(
SlateDoc,
on_delete=models.CASCADE,
related_name="acts"
)
act_number = models.IntegerField(verbose_name="Act", default=1)
tc_in = models.CharField(max_length=11, default="00:00:00:00")
tc_out = models.CharField(max_length=11, default="00:00:00:00")
dur = models.CharField(max_length=11, default="00:00:00:00")
objects = ActTimecodesQuerySet.as_manager()
class Meta:
ordering = ["act_number", "tc_in", "tc_out"]
#version info
"python_version": { "version": ==3.10" }
"django": { "version": "==4.1.1" },
"django-import-export": { "version": "==2.8.0"},
Here is the solution that I figured out.
The answer is very simple compared to what I was attempting to do - using the ForeignKey was totally unnecessary.
#admin.py
class SlateDocResource(resources.ModelResource):
actbreaks = Field(column_name="Act Breaks")
def dehydrate_actbreaks(self, slatedoc):
actbreaks = []
count = 1
for x in ActTimecodes.objects.filter(slatedoc_id=slatedoc.id):
tc_in = f"{count}_in"
tc_out = f"{count}_out"
duration = f"{count}_dur"
actbreak = {tc_in: x.tc_in, tc_out: x.tc_out, duration: x.dur}
actbreaks.append(actbreak)
count += 1
return actbreaks
the code above returns each actbreak as a dict in a list:
[{'tc_1_in': '01:00:00:00', 'tc_1_out': '01:13:34:00', 'act_1_dur': '00:13:34;00'}, {'tc_2_in': '01:13:36:00', 'tc_2_out': '01:19:03:00', 'act_2_dur': '00:05:26;28'}, {'tc_3_in': '01:19:05:00', 'tc_3_out': '01:26:13:00', 'act_3_dur': '00:07:08;02'}, {'tc_4_in': '01:26:15:00', 'tc_4_out': '01:31:16:00', 'act_4_dur': '00:05:01;02'}, {'tc_5_in': '01:31:18:00', 'tc_5_out': '01:37:39:00', 'act_5_dur': '00:06:21;00'}, {'tc_6_in': '01:37:41:00', 'tc_6_out': '01:44:10:00', 'act_6_dur': '00:06:29;00'}]

Signature of method __int__ does not match signature of base method in class This inspection detects inconsistencies in overriding method signatures

I am new to Python and currently facing issue with multiple inheritance.
Below is my code that i have written, for which i am getting following error
Signature of method 'Product.int()' does not match signature of base method in class 'RawMaterial'
Inspection info: This inspection detects inconsistencies in overriding method signatures.
Code Snippet:
class RawMaterial:
def __int__(self,rmname,rmstate):
print("Raw material class instantiated")
self.rmname = rmname
self.rmstate = rmstate
def raw_material_details(self):
print("Raw Material Name : ", self.rmname)
print("Raw Material State : ", self.rmstate)
class Worker:
def __int__(self,workid,wname,processid):
print("Worker class instantiated")
self.workid = workid
self.wname = wname
self.processid = processid
def worker_details(self):
print("Work ID : ", self.workid)
print("Worker Name: ", self.wname)
print("Process ID : ", self.processid)
class Product(RawMaterial, Worker):
def __int__(self, pname, pbatch, rmname, rmstate, workid, wname, processid):
print("Product class instantiated")
RawMaterial.__init__(rmname, rmstate)
Worker.__init__(workid, wname, processid)
self.pname = pname
self.pbatch = pbatch
def product_details(self):
print("Product Name : ",self.pname)
print("Product Batch : ",self.pbatch)
prod1 = Product("Pepsi","ZA443","Water","Liquid",12,"Alpha",443)
prod1.product_details()

why do we consider "skipping the steps" as "failed steps" with karate.abort() in karate report?

For my tests scenarios i am using "karate.abort()" function and this skips the steps beneath it if the condition is fulfilled.
But this is marking my complete test as failed because of the skipped steps .
Is there any way to mark the test case as PASSED if the karate.abort() is called and next steps are skipped?
Example:
Scenario Outline: Lambda API registration when ARN is invalid
Given url ApiAdminURL
And path AdminPath
And header apigateway-apikey = apiGatewayKey
And header apigateway-basepath = 'lambda-migration'
* json myReq = read('swagger-lambda.json')
* set myReq.apiConf.subscriptionTiers = <subscriptionTiers>
* set myReq.swagger.info.title = 'REGTEST_AUTO_Regression_Lambda_Quote_Function'
* set myReq.swagger.basePath = 'lambda-migration'
* set myReq.swagger.info.version = 'v1'
* set myReq.swagger.x-lambda-arn = '<arn>'
And request myReq
When method post
Then status <responseCode>
* eval if (responseStatus == 400) karate.abort()
* call read('Lambda-Sleep.feature')
* call read('Lambda-APIDefinition.feature')
* def responsefromsubscriber = call read('Lambda-Subscriber.feature')
{accessTokenforInvokation: '#(accessTokenforInvokation)', applicationId: '#
(applicationId)', subscribeToken: '#(subscribeToken)'}
* def AccessTokenforInvokation =
responsefromsubscriber.accessTokenforInvokation
* def ApplicationId = responsefromsubscriber.applicationId
* def SubscribeToken = responsefromsubscriber.subscribeToken
This is a bug that was fixed in a patch release: https://github.com/intuit/karate/issues/464
Can you just upgrade your Karate version to 0.8.0.1 and try again.

How to cast from virtual abstract class

Having this class definition
class CefBrowser : public virtual CefBase
How to cast from CefBrwoser * to CefBase * and reverse? assuming that both are not instanciable, they are loaded from C to CPP.

How to import files while loading a groovy class?

I am loading a class and doing some sql select statements, it seems that import groovy.sql.Sql needs to be imported. How can I load some library while loading a class?
My code (works fine if I remove Sql operations)
def fClass = new GroovyClassLoader().parseClass( new File( 'plugin/Pi.groovy' ) )
result=fClass.newInstance().buildTags( params, i9piparams, "userRoleCount")
pi.groovy
public class Pi{
def result
private def getDbUrl(dbdriver,dbhost,dbport,dbname)
{
return "$dbdriver:#$dbhost:$dbport:$dbname"
}
public def buildTags(Map<String,String> params,Map<String,String> i9piparams,def i9piType)
{
println params
println i9piparams
/*some Sql operation*/
Driver="oracle.jdbc.driver.OracleDriver"
dbdriver="jdbc:oracle:thin"
def url=getDbUrl(dbdriver,params.tns,i9piparams.dbport,i9piparams.dbname)
def sql = Sql.newInstance(url,params.u,params.x,Driver)
sql.eachRow("select name, value from v\$parameter where name = 'open_cursors'"){ row ->
result.name=row.name
result.value=row.value
}
}
}
Output
[pd:admin, u:zx5531d, tns:foner, dh:abds, dn:D35531, dp:11531, un:admin, x:cx15531]
[:, dbname:orcl, dbport:1521, dbtype:oracle]
Exception in thread "main" groovy.lang.GroovyRuntimeException: Could not find matching constructor for: groovy.sql.Sql(org.codehaus.groovy.runtime.GStringImpl, groovy.util.slurpersupport.Attributes, java.lang.String, java.lang.String)
.
.
.
Can you try changing your line:
def sql = Sql.newInstance(url,params.u,params.x,Driver)
to
def sql = Sql.newInstance( url, 'zx5531d', params.x, Driver )
What I suspect is that you need to call text() on the attributes when you read them from the XML, so that you get a String rather than a groovy.util.slurpersupport.Attributes class.
Also, why has Driver got a capital initial letter?
And (not sure what parameter is), but you probably want to change:
"select name, value from v\$parameter where name = 'open_cursors'"
to
"select name, value from v\${Sql.expand(parameter)} where name = 'open_cursors'"

Resources